How To Get UNIX Timestamp In JavaScript

The Unix timestamp is the number of seconds between a specific date and the Unix Epoch. In this tutorial, we have explained how to get Unix timestamp in milliseconds and seconds using javascript.

Get UNIX Timestamp in miliseconds:

To get timestamp in miliseconds, you can use Date.now() method

var getInMilisecond = Date.now();

Another method is with using valueOf() method, which returns the timestamp value of a Date object, which is the same as the total number of milliseconds since the Unix Epoch.

var getTimeSmp = new Date().valueOf();
Get Timestamp in Seconds:

To get timestamp in seconds, use following code.

var getInSeconds = Math.floor( Date.now() / 1000 );

Check changing the format of Date and Time in PHP.

Similar Posts