JavaScript tutorial:
setUTCMilliseconds method

 

Applies to: Date Object

The setUTCMilliseconds method is use to set the milliseconds value in the Date object using Universal Coordinated Time (UTC).

Syntax

objDate.setUTCMilliseconds(numMilli)

The numMilli argument is a numeric value equal to the milliseconds value.

Return

Returns the set milliseconds value in UTC format however it will not dispay if only alert the object unless call it directly using objDate.getUTCMilliseconds().

Example

To set the milliseconds using local time, use the setMilliseconds 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 setUTCMilliseconds method:

function SetUTCMSec(nmsec)
{
    var d, s;
    var sep = ":";
    d = new Date();
    d.setUTCMilliseconds(nmsec);
    s = "Current setting is ";
    s += d.toUTCString() + sep + d.getUTCMilliseconds();
    return(s);
}

document.write(SetUTCMSec(69));

To run the code above, paste it into JavaScript Editor, and click the Execute button

See also: Date Object Methods, getMilliseconds Method, getUTCMilliseconds Method, setMilliseconds Method