JavaScript & jQuery Tutorials

JS Home Right Arrow JS Reference Right Arrow Date Right Arrow setTime()

setTime()  Date  instance method

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
millisecondsIntAn integer.

  • If millisecondsInt is negative dates prior to 1 January 1970 00:00:00 UTC will be returned.

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');

Press the button below to action the above code:



Related Tutorials

JavaScript Intermediate Tutorials - Lesson 2 - Dates and Times




  

go to home page Homepage go to top of page Top