mozilla

Revision 423511 of Date.now()

  • Revision slug: Web/JavaScript/Reference/Global_Objects/Date/now
  • Revision title: Date.now
  • Revision id: 423511
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment

Revision Content

Summary

Returns the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.

Method of Date
Implemented in JavaScript 1.5
ECMAScript Edition ECMAScript 5th Edition

Syntax

var timeInMs = Date.now();

Parameters

None.

Description

The now() method returns the milliseconds elapsed since 1 January 1970 00:00:00 UTC up until now as a number.

Compatibility

This method was standardized in ECMA-262 5th edition. Engines which have not been updated to support this method can work around the absence of this method using the following shim:

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

Browser compatibility

Based on Kangax's compat table.

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 5 3 9 10.50 4
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

See also

  • {{domxref("window.performance.now")}} - provides timestamps with sub-millisecond resolution for use in measuring web page performance
  • {{domxref("console.time")}} / {{domxref("console.timeEnd")}}

Revision Source

<h2 id="Summary" name="Summary">Summary</h2>
<p>Returns the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.</p>
<table class="standard-table">
  <thead>
    <tr>
      <th class="header" colspan="2">Method of <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date"><code>Date</code></a></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Implemented in</td>
      <td>JavaScript 1.5</td>
    </tr>
    <tr>
      <td>ECMAScript Edition</td>
      <td>ECMAScript 5th Edition</td>
    </tr>
  </tbody>
</table>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
var timeInMs = Date.now();
</pre>
<h3 id="Parameters" name="Parameters">Parameters</h3>
<p>None.</p>
<h2 id="Description" name="Description">Description</h2>
<p>The <code>now()</code> method returns the milliseconds elapsed since 1 January 1970 00:00:00 UTC up until now as a <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>.</p>
<h2 id="Compatibility" name="Compatibility">Compatibility</h2>
<p>This method was standardized in ECMA-262 5th edition. Engines which have not been updated to support this method can work around the absence of this method using the following shim:</p>
<pre class="brush: js">
if (!Date.now) {
  Date.now = function now() {
    return new Date().getTime();
  };
}
</pre>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>Based on <a href="http://kangax.github.com/es5-compat-table/">Kangax's compat table</a>.</p>
<div>
  {{CompatibilityTable}}</div>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>5</td>
        <td>3</td>
        <td>9</td>
        <td>10.50</td>
        <td>4</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
  <li>{{domxref("window.performance.now")}} - provides timestamps with sub-millisecond resolution for use in measuring web page performance</li>
  <li>{{domxref("console.time")}} / {{domxref("console.timeEnd")}}</li>
</ul>
Revert to this revision