JavaScript Date setTime() Method
- Previous Page setSeconds()
- Next Page setUTCDate()
- Go Up One Level JavaScript Date Reference Manual
Definition and Usage
setTime()
The method sets the date and time by adding or subtracting a specified number of milliseconds from midnight on January 1, 1970.
Instance
Example 1
Add 1332403882588 milliseconds to January 1, 1970, and display the new date and time:
var d = new Date(); d.setTime(1332403882588);
Example 2
Subtract 1332403882588 milliseconds from January 1, 1970, and display the new date and time:
var d = new Date(); d.setTime(-1332403882588);
Syntax
Date.setTime(millisec)
Parameter Value
Parameter | Description |
---|---|
millisec | Required. The number of milliseconds to be added or subtracted from midnight on January 1, 1970. |
Technical Details
Return Value: | A numerical value representing the number of milliseconds between the Date object and midnight of January 1, 1970. |
---|---|
JavaScript Version: | ECMAScript 1 |
Browser Support
Method | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
setTime() | Support | Support | Support | Support | Support |
Related Pages
Tutorial:JavaScript Date
Tutorial:JavaScript Date Format
Tutorial:JavaScript Date Setting Methods
- Previous Page setSeconds()
- Next Page setUTCDate()
- Go Up One Level JavaScript Date Reference Manual