JavaScript tutorial:
getMilliseconds method

 

Applies to: Date Object

The getMilliseconds method is use to get the milliseconds value in a Date object using local time.

Syntax

objDate.getMilliseconds()

Return

Returns the milliseconds value in a Date object using local time.

Example

To get the number of milliseconds in Universal Coordinated Time (UTC), use the getUTCMilliseconds method.

The millisecond value returned can range from 0-999.

The following example illustrates the use of the getMilliseconds method:


function Time()
{
    var d, s = "The current local time is: ";
    var c = ":";
    d = new Date();
    s += d.getHours() + c;
    s += d.getMinutes() + c;
    s += d.getSeconds() + c;
    s += d.getMilliseconds();
    return(s);
}

document.write(Time());

millisec = "The current millisecond is: ";
d = new Date();
millisec += d.getMilliseconds();

document.write(millisec);

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

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