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
Fundamentals
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.
Concept
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.
Foundation
📝 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).
Cheat Sheet
⚡ Quick Reference
Goal
Code
Current timestamp (ms)
Date.now()
Unix seconds
Math.floor(Date.now() / 1000)
Elapsed milliseconds
Date.now() - start
Equivalent instance call
new Date().getTime()
Date from timestamp
new Date(Date.now())
Deadline check
Date.now() > deadlineMs
Compare
📋 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
Hands-On
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.
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");
They usually match when called in the same millisecond. If a tick passes between calls, values can differ by 1 ms—that is normal.
Applications
🚀 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).
Important
📝 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().
Compatibility
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 ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · 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.
Wrap Up
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.
Your foundation for current timestamps in JavaScript.
5
Core concepts
📝01
Syntax
Date.now()
API
⚡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.