JavaScript Date now() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Static · epoch ms

What You’ll Learn

Date.now() returns the current number of milliseconds since the Unix epoch without creating a Date object. This guide covers syntax, timing patterns, seconds conversion, and how it compares to getTime().

01

Syntax

Date.now()

02

Static

On Date

03

Epoch ms

Large integer

04

Timing

Start / end

05

vs getTime

Same value

06

/ 1000

Unix seconds

Introduction

Measuring how long code takes, stamping log entries, and generating client-side timestamps all need the current time as a number. JavaScript provides Date.now()—a static method that returns epoch milliseconds directly, with no new Date() required.

It is the most common shortcut for “what time is it right now?” in milliseconds. To read the timestamp from an existing Date instance, use getTime() instead.

Understanding the Date.now() Method

Date.now() is a static method on the Date constructor. You call it as Date.now(), not on a date instance. It returns the same millisecond value as new Date().getTime().

The result counts milliseconds since January 1, 1970 00:00:00 UTC. That value is timezone-independent—everyone on Earth gets the same number at the same instant.

💡
Beginner Tip

Prefer Date.now() over new Date().getTime() when you only need the current timestamp—it avoids creating an object you never use.

📝 Syntax

JavaScript
Date.now()

Parameters

  • None.

Return value

  • Number of milliseconds since the Unix epoch at call time.
  • Always a finite number in normal environments (not NaN).

⚡ Quick Reference

GoalCode
Current timestamp (ms)Date.now()
Unix secondsMath.floor(Date.now() / 1000)
Elapsed millisecondsDate.now() - start
Equivalent instance callnew Date().getTime()
Date from timestampnew Date(Date.now())
Deadline checkDate.now() > deadlineMs

📋 Date.now() vs Similar APIs

These APIs involve time but serve different jobs. Pick the one that matches your task.

Date.now()
now ms

Static current time

getTime()
epoch ms

On a Date instance

valueOf()
same ms

Coercion hook

performance.now()
elapsed

High-res benchmark

Examples Gallery

Open DevTools Console (F12) or use Try-it links. Timestamps from “now” will differ on your machine—that is expected.

📚 Getting Started

Read the current epoch milliseconds with one static call.

Example 1 — Get the Current Timestamp

Call Date.now() to read milliseconds since the Unix epoch.

JavaScript
const timestamp = Date.now();

console.log("Timestamp (ms):", timestamp);
Try It Yourself

How It Works

The number grows every millisecond. Store it in a variable when you need to compare or subtract later.

📈 Practical Patterns

Seconds conversion, timing, logging, and API comparison.

Example 2 — Convert to Unix Seconds

Many APIs expect whole seconds, not milliseconds. Divide by 1000 and floor the result.

JavaScript
const unixSeconds = Math.floor(Date.now() / 1000);

console.log("Unix seconds:", unixSeconds);
Try It Yourself

How It Works

Date.now() is always in milliseconds. Dividing by 1000 drops the sub-second fraction for second-granularity APIs.

Example 3 — Measure Code Execution Time

Record a start timestamp, run work, then subtract to get elapsed milliseconds.

JavaScript
const start = Date.now();

// Simulated work
let sum = 0;
for (let i = 0; i < 100000; i++) sum += i;

const elapsed = Date.now() - start;
console.log("Elapsed:", elapsed, "ms");
Try It Yourself

How It Works

Subtracting two Date.now() values gives elapsed wall-clock milliseconds. For sub-millisecond browser benchmarks, consider performance.now().

Example 4 — Stamp Log Entries with a Timestamp

Attach Date.now() to events for simple client-side logging.

JavaScript
function logEvent(message) {
  const entry = { at: Date.now(), message };
  console.log(JSON.stringify(entry));
}

logEvent("User clicked Save");
Try It Yourself

How It Works

Epoch milliseconds sort chronologically as numbers. For human-readable logs, convert with new Date(entry.at).toISOString().

Example 5 — Compare Date.now() and getTime()

Both read the current instant—they should match when called back-to-back.

JavaScript
const fromNow = Date.now();
const fromGetTime = new Date().getTime();

console.log("Date.now():", fromNow);
console.log("getTime():", fromGetTime);
console.log("Equal:", fromNow === fromGetTime);
Try It Yourself

How It Works

They usually match when called in the same millisecond. If a tick passes between calls, values can differ by 1 ms—that is normal.

🚀 Common Use Cases

  • Performance timing — measure how long a function takes.
  • Cache expiry — compare Date.now() to a stored deadline.
  • Rate limiting — track last request time in milliseconds.
  • Event logs — stamp client actions with epoch ms.
  • Session timeouts — detect idle time since last activity.
  • Simple IDs — combine with randomness when uniqueness matters.

🧠 How Date.now() Returns the Current Time

1

Static call

You invoke Date.now() on the constructor, not an instance.

Date.now()
2

Read system clock

The engine reads the current wall-clock instant from the host.

Host time
3

Epoch offset

Milliseconds since Jan 1, 1970 00:00:00 UTC are computed.

Unix epoch
4

Use the number

Subtract, compare, store, or pass to new Date(ms).

📝 Notes

  • Date.now() returns milliseconds, not seconds.
  • It is static—do not call it on a Date instance.
  • Equivalent to new Date().getTime() but avoids object allocation.
  • For micro-benchmarks in browsers, performance.now() may be more precise.
  • Wall-clock time can jump if the system clock is adjusted—not ideal for long-running timers alone.
  • For unique IDs in production, add randomness or use crypto.randomUUID().

Browser & Runtime Support

Date.now() has been available since ES5 (2009). It works in every modern browser and all Node.js versions.

Baseline · ES5

Date.now()

Supported in Chrome, Firefox, Safari, Edge, Internet Explorer 9+, and all Node.js versions. No polyfill required.

99% Universal API
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Date.now() Excellent

Bottom line: Safe everywhere. Remember milliseconds, not seconds, and prefer it over new Date().getTime() for current time.

Conclusion

Date.now() is the simplest way to read the current Unix timestamp in JavaScript. Use it for timing, deadlines, and logging; convert to seconds when APIs require it; and reach for getTime() when you already have a Date object.

Next, learn Date.parse() to turn date strings into timestamps, or review getTime() for instance-based reads.

💡 Best Practices

✅ Do

  • Use Date.now() directly for current time
  • Store start time before long operations
  • Divide by 1000 for Unix seconds
  • Compare timestamps with < and >
  • Convert to ISO strings for human-readable logs

❌ Don’t

  • Assume the value is in seconds
  • Create new Date() only to call getTime()
  • Rely on it alone for guaranteed-unique IDs
  • Confuse it with getSeconds() (0–59 clock part)
  • Use wall-clock time for sub-ms browser benchmarks

Key Takeaways

Knowledge Unlocked

Five things to remember about Date.now()

Your foundation for current timestamps in JavaScript.

5
Core concepts
02

Static

On Date.

Type
🔢 03

Epoch ms

Since 1970.

Unit
04

Timing

end - start.

Pattern
05

/ 1000

Unix sec.

Convert

❓ Frequently Asked Questions

The number of milliseconds since January 1, 1970 00:00:00 UTC (the Unix epoch) at the moment it is called. It is a large integer, not a clock component like 0–59.
No. Date.now() is a static method on the Date constructor. Call Date.now() directly—no new Date() required.
Date.now() is static and returns the current epoch milliseconds. getTime() is an instance method on an existing Date. For the current time, new Date().getTime() and Date.now() return the same value.
Milliseconds. Divide by 1000 and use Math.floor when you need whole Unix seconds.
Date.now() returns wall-clock epoch milliseconds (can jump if the system clock changes). performance.now() returns high-resolution elapsed milliseconds since page load and is better for micro-benchmarks in the browser.
It works for simple client-side IDs, but two calls in the same millisecond can collide. For production IDs, prefer crypto.randomUUID() or a dedicated ID generator.
Did you know?

Date.now() and new Date().getTime() return the same millisecond value—but only Date.now() skips creating a Date object you never use.

Continue to Date.parse()

Learn how to parse date strings into epoch milliseconds.

Date.parse() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful