AI Code

JavaScript Timestamps


  • millisecondsAndMicrosecondsSincePageLoad =;
  • millisecondsSinceYear1970 =;
  • millisecondsSinceYear1970 = (new Date()).getTime();

Remarks is available in modern web browsers and provides reliable timestamps with sub-millisecond resolution.

Since and (new Date()).getTime() are based on the system time, they often get skewed by a few milliseconds when the system time is automatically synchronized.

High-resolution timestamps returns a precise timestamp: The number of milliseconds, including microseconds, since the current web page started to load.

More generally, it returns the time elapsed since the performanceTiming.navigationStart event.

t =;

For example, in a web browser's main context, returns 6288.319 if the web page began to load 6288 milliseconds and 319 microseconds ago.

Low-resolution timestamps returns the number of whole milliseconds that have elapsed since 1 January 1970 00:00:00 UTC.

t =;

For example, returns 1461069314 if it was called on 19 April 2016 at 12:35:14 GMT.

Support for legacy browsers

In older browsers where is unavailable, use (new Date()).getTime() instead:

t = (new Date()).getTime();

Or, to provide a function for use in older browsers, use this polyfill:

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

Get Timestamp in Seconds

To get the timestamp in seconds

Math.floor((new Date().getTime()) / 1000)

Got any JavaScript Question?