The getUTCMilliseconds() method returns the milliseconds ranged from 0 to 999 from the date object, according to universal time.
The getUTCMilliseconds() method returns the milliseconds ranged from 0 to 999 from the date object, according to universal time.
UTC time is the same as GMT time.
Date.getUTCMilliseconds()
None
A Number, from 0-999, representing milliseconds
Return the milliseconds, according to UTC:
//display milliseconds, according to UTC. var d = new Date(); var n = d.getUTCMilliseconds(); console.log(n);//from ww w . j a va 2 s. c om //Return the UTC milliseconds from a specific date and time: //display milliseconds of a specific date-time, according to UTC. var d = new Date("July 21, 2010 01:15:00:195"); var n = d.getUTCMilliseconds(); console.log(n);
Using getHours(), getMinutes(), getSeconds(), and getMilliseconds() to display the UTC time (with milliseconds):
//display the UTC time. function addZero(x,n) { while (x.toString().length < n) { x = "0" + x; }/*from w w w.j a v a2 s. c o m*/ return x; } var d = new Date(); var h = addZero(d.getUTCHours(), 2); var m = addZero(d.getUTCMinutes(), 2); var s = addZero(d.getUTCSeconds(), 2); var ms = addZero(d.getUTCMilliseconds(), 3); console.log( h + ":" + m + ":" + s + ":" + ms);