Date.prototype.setTime() changes the timestamp for this date — the number of milliseconds since the Unix epoch (midnight, January 1, 1970, UTC) (MDN). It mutates the Date in place and returns the new timestamp.
Remember
date.setTime(timeValue)
timeValue → milliseconds since 1970-01-01T00:00:00.000Z
→ returns new timestamp (ms)
→ mutates date
setTime(0) // Unix epoch
setTime(other.getTime()) // copy instant
setTime(date.getTime() + 5*60*1000) // +5 minutes
Syntax
Call date.setTime. Start with this line.
JavaScript
date.setTime(timeValue)
Call
What it does
date.setTime(timeValue)
Primary signature.
date.setTime(...)
Call with the arguments your case needs.
Built into JavaScript. Call setTime(...) on a Date instance — no import required.
Library declarations
JavaScript
date.setTime(timeValue)
Parameters
Parameter
Description
timeValue
Required. Epoch milliseconds (UTC-based instant)
Return Value
Return Value
Description
*
New epoch ms (number), not the Date
JavaScript Examples
Example 1 — Copy an Instant
MDN-style: assign one Date’s timestamp onto another with setTime().
ISO.toISOString() shows the UTC string for that instant.
Compatibility
Browser & Runtime Support
Date.prototype.setTime() is part of the language from early ECMAScript and is Baseline Widely available (MDN).
✓ Baseline · Widely available
Date.prototype.setTime()
Supported in every modern browser and Node.js. No polyfill needed for ordinary web apps.
99%Modern browser support
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.setTime()Excellent
Bottom line: Safe everywhere. Focus on mutation, Invalid Date from NaN, and choosing setTime vs field setters.
Frequently Asked Questions
It sets a Date to the instant represented by epoch milliseconds — milliseconds since January 1, 1970 00:00:00 UTC. The Date mutates in place and the method returns that millisecond number.
getTime() reads the current epoch milliseconds. setTime(ms) writes a new instant from epoch milliseconds. They are the read/write pair for the full timestamp.
Field setters change one local/UTC clock component (with overflow). setTime() replaces the entire instant in one call — ideal when you already have a Unix timestamp.
Yes. date.setTime(date.getTime() + 5 * 60 * 1000) shifts the instant forward by five minutes in milliseconds (MDN).
No. It returns a number (epoch milliseconds). Call setters on the Date variable — do not chain on the return value.
The Date becomes invalid. setTime() returns NaN, and Number.isNaN(date.getTime()) is true.