JavaScript & jQuery Tutorials

JS Home Right Arrow JS Reference Right Arrow Date Right Arrow UTC()

UTC()  Date  class method

Description

Accepts a user input date and returns an integer value representing the milliseconds elapsed time since 1 January 1900 00:00:00 UTC.

  • Date.UTC() uses Universal time while the Date object uses local time.
  • Date.UTC() returns an integer representing number of milliseconds since 1 January 1900 00:00:00 UTC to specified date.
  • Date.UTC() returns negative integers representing the number of milliseconds prior to 1 January 1900 00:00:00 UTC to specified date. Dates go back as far as 1 January 1900 00:00:00 UTC.
  • Like all class methods now() should be used on the class rather than an instance of the class.

Syntax


Signature Description
aDate.UTC(yearInt, monthInt[, dayInt[, hourInt
         [, minuteInt[, secondInt[, millisecondInt]]]]])
Returns a reference to the function that created the prototype.

Parameters


Parameter Description
yearIntAn integer specifying the year.
monthIntAn integer in the range 0-11. January=0, February=1 etc.
  • For specified values outside the ranges above the UTC() method will try and set the date accordingly.
dayIntAn integer in the range 1-31.
  • A value of 0 will set the date to the last day of the previous month.
  • Negative values will try and set date to last day of previous month and then subtract integer amount.
hourIntAn integer in the range 0-23.
minuteIntAn integer in the range 0-59.
secondIntAn integer in the range 0-59.
millisecondIntAn integer in the range 0-999.
For specified values outside the ranges above the UTC() method will try and set the date accordingly.

Examples

The code below shows examples of the UTC() method of Date.


// Show elapsed time in Milliseconds.
var milliDate = Date.UTC(-34, 11); 
alert(milliDate + ' = Milliseconds since  1 January 1970 00:00:00 UTC.')
// Convert back to a date.
var aDate = new Date(milliDate);
alert(aDate + ' = Converted back to a date.');
// Show elapsed time in Milliseconds.
var milliDate = Date.UTC(2012, 11, -6, 0, 0, 0, 0); 
alert(milliDate + ' = Milliseconds since  1 January 1970 00:00:00 UTC.')
// Convert back to a date.
var aDate = new Date(milliDate);
alert(aDate + ' = Converted back to a date.');

Press the button below to action the above code:

Related Tutorials

JavaScript Intermediate Tutorials - Lesson 2 - Dates and Times



  

go to home page Homepage go to top of page Top