JavaScript setMilliseconds method





The setMilliseconds method sets the milliseconds value of the point in time stored in a Date object.

Besides, it can also be used to increase or decrease the point in time of that object in a given quantity of milliseconds.

The value returned by this method is the quantity of milliseconds passed since January 1st 1970 until the point in time stored in the Date object once it has been modified.


Syntax

myDate.setMilliseconds( milliseconds )

With:
  • milliseconds being an integer number that, when it is between 0 and 999, changes only the milliseconds value of the point in time stored in a Date object. Any value outside that range increases or decreases the point in time stored in a Date object in a quantity equal to the range's limit being exceeded plus the remaining milliseconds.
  • myDate being an object based on the Date object.


Example

The following code uses the setMilliseconds method to set the millisecond value of the point in time stored in a Date object to 500:

<script type="text/javascript">

var myDate = new Date();

myDate.setMilliseconds(500);

document.write("The millisecond value of the point in time stored in myDate is: " + myDate.getMilliseconds());

</script>


Technical Details

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





JavaScript Manual >> Date Object >> setMilliseconds Method





© Copyright 2010-2016 ROM Cartridge