JavaScript setTime()Method
Examples
In this example, we will add 1332403882588 milliseconds to January 1, 1970, and display the new date and time:
var d = new Date();
d.setTime(1332403882588);
d.setTime(1332403882588);
dOutput result:
Try it Yourself »
Definition and Usage
The setTime() method sets the Date object in milliseconds.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the setTime() method.
Syntax
Date.setTime(millisec)
Parameter Values
| Parameter | Description |
|---|---|
| millisec | Required. The number of milliseconds between the date and time to be set and midnight of January 1, 1970 GMT. This type of millisecond value can be passed to the Date() constructor, and can be obtained by calling the Date.UTC() and Date.parse() methods. Representing the date in milliseconds makes it independent of time zone. |
Return Value
| Type | Description |
|---|---|
| Number | Returns the parameter millisec. Before ECMAScript standardization, this method did not return a value. |
Technical Details
| JavaScript Version: | 1.0 |
|---|
More Examples
Example
In this example, we will subtract 1332403882588 milliseconds from 1970/01/01 and display the new date and time:
var d = new Date();
d.setTime(-1332403882588);
d.setTime(-1332403882588);
dResult output:
Try it Yourself »
Other Extensions
JavaScript Date Object