setTime()
Date
instance method
JS Home <<
JS Reference <<
Date <<
setTime()
Description
Sets the locale specific number of milliseconds since 1 January 1970 00:00:00 UTC
.
Syntax
Signature | Description |
---|---|
aDate.setTime(millisecondsInt) | Sets the locale specific number of milliseconds since 1 January 1970 00:00:00 UTC . |
Parameters
Parameter | Description |
---|---|
millisecondsInt | An integer.
|
Examples
The code below shows an example of the setTime()
method of Date
.
// Create a Date instance for the current date and time.
var todaysDate = new Date();
alert(todaysDate);
// Set number milliseconds since 1 January 1970 00:00:00 UTC.
todaysDate.setTime(1000000000);
alert(todaysDate + ' - 1970 +1000000000 milliseconds');
// Set number milliseconds prior 1 January 1970 00:00:00 UTC.
todaysDate.setTime(-1000000000);
alert(todaysDate + ' - 1970 -1000000000 milliseconds');
Related Tutorials
JavaScript Intermediate Tutorials - Lesson 2 - Dates and Times