UTC()
Date
class methodS2C Home
« Globals « Date « UTC()
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 theDate
object uses local time.Date.UTC()
returns an integer representing the number of milliseconds since1 January 1900 00:00:00 UTC
to specified date.Date.UTC()
returns negative integers representing the number of milliseconds prior to1 January 1900 00:00:00 UTC
to specified date. Dates go back as far as1 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 |
---|---|
yearInt | An integer specifying the year. |
monthInt | An integer in the range 0-11. January=0, February=1 etc.
|
dayInt | An integer in the range 1-31.
|
hourInt | An integer in the range 0-23. |
minuteInt | An integer in the range 0-59. |
secondInt | An integer in the range 0-59. |
millisecondInt | An 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.');
Related Tutorials
JavaScript Intermediate Tutorials - Lesson 2 - Dates and Times