JavaScript Date getUTCMilliseconds() Method

Definition and Usage

getUTCMilliseconds() The method returns the milliseconds (from 0 to 999) for a specified date and time based on world time.

When calculating dates, the UTC methods assume the date object is local time and date.

Tip:Coordinated Universal Time (UTC) is the standard time set by the world time standard.

Note:UTC time is the same as GMT (Greenwich Mean Time).

Example

Example 1

Return milliseconds based on UTC:

var d = new Date();
var n = d.getUTCMilliseconds();

Try It Yourself

Example 2

Return the UTC milliseconds for a specific date and time:

var d = new Date("July 21, 1983 01:15:00:195");
var n = d.getUTCMilliseconds();

Try It Yourself

Example 3

Display UTC time (in milliseconds) using getHours(), getMinutes(), getSeconds(), and getMilliseconds():

function addZero(x, n) {
  while (x.toString().length < n) {
    x = "0" + x;
  }
  return x;
}
function myFunction() {
  var d = new Date();
  var x = document.getElementById("demo");
  var h = addZero(d.getUTCHours(), 2);
  var m = addZero(d.getUTCMinutes(), 2);
  var s = addZero(d.getUTCSeconds(), 2);
  var ms = addZero(d.getUTCMilliseconds(), 3);
  x.innerHTML = h + ":" + m + ":" + s + ":" + ms;
}

Try It Yourself

Syntax

Date.getUTCMilliseconds()

Parameters

No parameters.

Technical Details

Return Value: Numeric value, from 0-999, representing milliseconds.
JavaScript Version: ECMAScript 1

Browser Support

Method Chrome IE Firefox Safari Opera
getUTCMilliseconds() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Date

Tutorial:JavaScript Date Format

Tutorial:JavaScript Object Constructor