JavaScript Date UTC() method

Definition and usage

UTC() The method returns the milliseconds between the specified date and midnight on January 1, 1970 based on world time.

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

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

Example

Example 1

Return the milliseconds between the specified date and midnight on January 1, 1970:

var d = Date.UTC(2012, 02, 30);

Try it yourself

Example 2

Create a date object using UTC time instead of local time:

var d = new Date(Date.UTC(2012, 02, 30));

Try it yourself

Syntax

Date.UTC(year, month, day, hours, minutes, seconds, millisec)

Parameter value

Parameter Description
year Required. Represents the four-digit year value, allowing negative values.
month

Required. Represents the integer of the month.

The expected value is 0-11, but other values are allowed:

  • -1 will cause the last month of the previous year
  • 12 will cause the first month of the next year
  • 13 will cause the second month of the next year
day

Optional. Integer, representing the day of the month.

The expected value is 1-31, but other values are allowed:

  • 0 will cause the last hour of the previous month
  • -1 will cause one hour before the last hour of the previous month

If a month has 31 days:

  • 32 will cause the first day of the next month

If a month has 30 days:

  • 32 will cause the second day of the next month
hour

Optional. Default is 0. Represents the integer part of hours.

The expected value is 0-23, but other values are allowed:

  • -1 will cause the last hour of the previous day
  • 24 will cause the first hour of the next day
min

Optional. Default is 0. Represents the integer part of minutes.

The expected value is 0-59, but other values are allowed:

  • -1 will cause the last minute of the previous hour
  • 60 will cause the first minute of the next hour
sec

Optional. Default is 0. Represents the integer part of seconds

The expected value is 0-59, but other values are allowed:

  • -1 will cause the last second of the previous minute
  • 60 will cause the first second of the next minute
millisec

Optional. Default is 0. Represents the integer part of milliseconds

The expected value is 0-999, but other values are allowed:

  • -1 will cause the last millisecond of the previous second
  • 1000 will cause the first millisecond of the next second

Technical details

Return value: A number representing the milliseconds between the specified date and time and midnight on January 1, 1970.
JavaScript version: ECMAScript 1

Browser Support

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

Related Pages

Tutorial:JavaScript Date

Tutorial:JavaScript Date Format