JavaScript setTime() Method
Example
In this example, we will add 1332403882588 milliseconds to January 01, 1970 and display the new date and time:
var d = new Date();
d.setTime(1332403882588);
d Output result:
Try it »
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
| Parameters | Description |
|---|---|
| millisec | Required. The number of milliseconds between the date and time to be set and midnight on 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 dates in milliseconds makes them independent of time zones. |
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 Result output:
Try it »
JavaScript Date object