How to use JavaScript to Get Timestamps Explained with Examples

You can use to get the current timestamp in milliseconds.

You can easily convert the timestamp to seconds like this: Math.floor( / 1000)

If your browser does not support , you can use new Date().getTime() to get the timestamp in milliseconds.

Unix Timestamp is number of seconds elapsed since 01/01/1970, 00:00:00 UTC. The Unix timestamp will break on 01/19/2038.


For older browsers, we can use:

if (! { = function now() {
    return new Date().getTime();
1 Like