Applies to: Date Object
The setMilliseconds method is use to set the milliseconds value in the Date object using local time. It return in milliseconds. To convert the millisecond to string use obj.toLocaleString( ).
Syntax
objDate.setMilliseconds(numMilli)
The numMilli argument is a numeric value equal to the millisecond value.
Return millisecond
Returns set time in milliseconds.
Example
All set methods taking optional arguments use the value returned from corresponding get methods, if you do not specify an optional argument. For example, if the numMonth argument is optional, but not specified, JavaScript uses the value returned from the getMonth method.
To set the milliseconds value using Universal Coordinated Time (UTC), use the setUTCMilliseconds method.
If the value of numMilli is greater than 999 or is a negative number, the stored number of seconds (and minutes, hours, and so forth if necessary) is incremented an appropriate amount.
The following example illustrates the use of the setMilliseconds method:
function SetMSec(nmsec)
{
var d, s;
var sep = ":";
d = new Date();
d.setMilliseconds(nmsec);
s = "Current setting is ";
s += d.toLocaleString() + sep + d.getMilliseconds();
return(s);
}
document.write(SetMSec(36));
|
To run the code above, paste it into JavaScript Editor, and click the Execute button
See also: Date Object Methods, getMilliseconds Method, getUTCMilliseconds Method, setUTCMilliseconds Method |