Easy Tutorial
❮ Met Canvas Drawimage Prop Style Margin ❯

JavaScript setTime() Method

JavaScript Date Object

Example

In this example, we will add 1332403882588 milliseconds to January 1, 1970, and display the new date and time:

d output result:


Definition and Usage

The setTime() method sets the Date object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC.


Browser Support

All major browsers support the setTime() method.


Syntax

Parameter Values

Parameter Description
millisec Required. The number of milliseconds since January 1, 1970, 00:00:00 UTC to set the date to. 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. Prior to 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 January 1, 1970, and display the new date and time:

var d = new Date();
d.setTime(-1332403882588);

d result output:

var d = new Date();
d.setTime(-1332403882588);
document.write(d);

JavaScript Date Object

❮ Met Canvas Drawimage Prop Style Margin ❯