Now you can listen to this article with the Online Text Reader


JavaScript setTime Method





The setTime method sets the point in time of a Date object by adding or subtracting a quantity of milliseconds to the beginning of January 1st 1970 of the Coordinated Universal Time.


Syntax

myDate.setTime( milliseconds )

With:
  • milliseconds being an integer number either positive or negative equal to the difference in milliseconds since the point in time that is being assigned to the Date object and January 1st 1970 of the Coordinated Universal Time.
  • myDate being an object based on the Date object.


Example

The following code uses the setTime method to add 1000 milliseconds to January 1st 1970 of the Coordinated Universal Time.

<script type="text/javascript">

var myDate = new Date();

myDate.setTime(0);

var outcome = "After adding 1000 milliseconds to the following point in time:<br /><br/>";
outcome += myDate.toUTCString() + ",<br /><br />";

myDate.setTime(1000);

outcome += "the resulting point in time is:<br /><br/> ";
outcome += myDate.toUTCString() + ".<br /><br />";

document.write(outcome);

</script>


Technical Details

The setTime method belongs to the Date object, it is available since the version 1.0 of JavaScript, and it is supported in all major browsers.





JavaScript Manual >> Date Object >> setTime Method





© Copyright 2010-2018 ROM Cartridge



Books to Read and Listen to Online