JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

Date.UTC() Function

Name

Date.UTC() Function---convert a date specification to milliseconds

Availability

Navigator 2.0, Internet Explorer 3.0

Synopsis

Date.UTC(year, month, day [, hours [, minutes [, seconds]]]);

Arguments

year

The year minus 1900. For example, specify 96 for the year 1996.

month

The month, specified as an integer from 0 (January) to 11 (December)

day

The day of the month, specified as an integer from 1 to 31. Note that this argument uses 1 as its lowest value, while other arguments use 0 as their lowest value.

hours

The hour, specified as an integer from 0 (midnight) to 23 (11 p.m.). This argument may be omitted if minutes and seconds are also omitted.

minutes

The minutes in the hour, specified as an integer from 0 to 59. This argument may be omitted if seconds is also omitted.

seconds

The seconds in the minute, specified as an integer from 0 to 59. This argument may be omitted.

Returns

The number of milliseconds between midnight on January 1st, 1970, UTC and the time specified (also in UTC) by the arguments.

Description

Date.UTC() is a function with a name that begins with "Date". It is related to the Date object, but it is not a method of the Date object, and is not invoked on a Date object. It is always invoked as Date.UTC(), not as date.UTC() on some Date object date.

The arguments to Date.UTC() specify a date and time, and are understood to be in UTC (Universal Coordinated Time)--i.e., they are in the GMT time zone. The specified UTC time is converted to the millisecond format, which can be used by the Date() constructor method, and by the Date.setTime() method.

Usage

The Date() constructor method can accept date and time arguments identical to those that Date.UTC() accepts. The difference is that the Date() constructor assumes local time, while Date.UTC() assumes UTC. To create a Date object using a UTC time specification, you can use code like this:

d = new Date(Date.UTC(96, 4, 8, 16, 30));

Bugs

In Navigator 2.0, Date.UTC() does not compute the correct number of milliseconds.

See Also

"Date", "Date.parse()", "Date.setTime()"


Previous Home Next
Date.toLocaleString() Book Index defaultStatus

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell
Hosted by uCoz