Aptana Studio ヘルプ > Reference > JavaScript Core

Date : Object
Return to: JavaScript Core index

Lets you work with dates and times.

Platform Support

IE Mozilla Netscape Opera Safari
3.0+ 1.0+ 2.0+ 7.0+ 1.0+

Constructors

Constructor Action IE Mozilla Netscape Opera Safari
Date Constructor([Number milliseconds,] [String dateString,] [Object yr_num, mo_num, day_num,] [Object hr_num, min_num, sec_num, ms_num]) : Date
Creates a new instance of a Date object.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+

Properties

Property Action IE Mozilla Netscape Opera Safari
constructor : Function
Specifies the function that creates an object's prototype. Note that the value of this property is a reference to the function itself, not a string containing the function's name.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+
prototype : Date
Represents the prototype for this class. You can use the prototype to add properties or methods to all instances of a class.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+

Functions

Method Action IE Mozilla Netscape Opera Safari
getDate() : Number
Returns the day of the month for the specified date according to local time.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
getDay() : Number
Returns a number representing the day of the week for the specified date (according to local time).
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
getFullYear() : Number
Returns the year of the specified date according to local time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
getHours() : Number
Returns the hour for the specified date according to local time.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
getMilliseconds() : Number
Returns the number of milliseconds in the specified date according to local time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
getMinutes() : Number
Returns the minutes in the specified date according to local time.
Show Details 4.0+ 1.0+ 2.0+ 7.0+ 1.0+
getMonth() : Number
Returns the month (from 0-11) in the specified date according to local time.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
getSeconds() : Number
Returns the seconds in the specified date according to local time.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
getTime() : Number
Returns the numeric value corresponding to the time for the specified date according to universal time.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Returns the time-zone offset in minutes for the current locale.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
getUTCDate() : Number
Returns the day (date) of the month in the specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
getUTCDay() : Number
Returns the day of the week in the specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
getUTCFullYear() : Number
Returns the year in the specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
getUTCHours() : Number
Returns the hours in the specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
Returns the milliseconds in the specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
getUTCMinutes() : Number
Returns the minutes in the specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
getUTCMonth() : Number
Returns the month of the specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
getUTCSeconds() : Number
Returns the seconds in the specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
getYear() : Number
Returns the year in the specified date according to local time.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
now() : Number
Returns the number of milliseconds passed since 1970-01-01 00:00:00 UTC.
Show Details no 1.0+ no no no
static parse(String dateString) : Number
Parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00, local time.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
setDate(Number dayValue) : Number
Sets the day of the month for a specified date according to local time.
Show Details 4.0+ 1.0+ 2.0+ 7.0+ 1.0+
setFullYear(Number yearValue, [Number monthValue,] [Number dayValue]) : Number
Sets the full year for a specified date according to local time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
setHours(Number hoursValue, [Number minutesValue,] [Number secondsValue,] [Number msValue]) : Number
Sets the hours for a specified date according to local time.
Show Details 4.0+ 1.0+ 2.0+ 7.0+ 1.0+
setMilliseconds(Number millisecondsValue) : Number
Sets the milliseconds for a specified date according to local time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
setMinutes(Number minutesValue, [Number secondsValue,] [Number msValue]) : Number
Sets the minutes for a specified date according to local time.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
setMonth(Number monthValue, [Number dayValue]) : Number
Set the month for a specified date according to local time.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
setSeconds(Number secondsValue, [Number msValue]) : Number
Sets the seconds for a specified date according to local time.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
setTime(Number timeValue) : Number
Sets the value of a Date object according to local time.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
setUTCDate(Number dayValue) : Number
Sets the day of the month for a specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
setUTCFullYear(Number yearValue, [Number monthValue,] [Number dayValue]) : Number
Sets the full year for a specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
setUTCHours(Number hoursValue, [Number minutesValue,] [Number secondsValue,] [Number msValue]) : Number
Sets the hour for a specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
setUTCMilliseconds(Number millisecondsValue) : Number
Sets the milliseconds for a specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
setUTCMinutes(Number minutesValue, [Number secondsValue,] [Number msValue]) : Number
Sets the minutes for a specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
setUTCMonth(Number monthValue, [Number dayValue]) : Number
Sets the month for a specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
setUTCSeconds(Number secondsValue, [Number msValue]) : Number
Sets the seconds for a specified date according to universal time.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
setYear(Number yearValue) : Number
Sets the year for a specified date according to local time.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
toDateString() : String
Returns a string version of the Date object expressed in local time.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+
toGMTString() : String
Converts a date to a string, using Internet GMT conventions.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+
Converts a date to a string, returning the "date" portion using the current locale's conventions.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
toLocaleString() : String
Converts a date to a string, using the current locale's conventions.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Converts a date to a string, returning the "date" portion using the current locale's conventions.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
toSource() : String
Returns a string representing the source code of a Date object.
Show Details 3.0+ 1.0+ 2.0+ no no
toString() : String
Returns a string representing the specified Date object.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+
toTimeString() : String
Returns a string representation of the time portion of a Date object, expressed in local time.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+
toUTCString() : String
Converts a date to a string, using the universal time convention.
Show Details 4.0+ 1.0+ 4.06+ 7.0+ 1.0+
static UTC(Object year, Number month, [Number date,] [Number hrs,] [Number min,] [Number sec,] [Number ms]) : Number
Accepts the same parameters as the longest form of the constructor, and returns the number of milliseconds in a Date object since January 1, 1970, 00:00:00, universal time.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
valueOf() : Number
Returns the primitive value of a Date object.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+

Several ways to assign dates

The following examples show several ways to assign dates:

today = new Date();
         birthday = new Date("December 17, 1995 03:24:00");
         birthday = new Date(95,11,17);
         birthday = new Date(95,11,17,3,24,0);

Remarks

If you supply no arguments, the constructor creates a Date object for today's date and time according to local time. If you supply some arguments but not others, the missing arguments are set to 0. If you supply any arguments, you must supply at least the year, month, and day. You can omit the hours, minutes, seconds, and milliseconds.

The date is measured in milliseconds since midnight 01 January, 1970 UTC. A day holds 86,400,000 milliseconds. The Date object range is -100,000,000 days to 100,000,000 days relative to 01 January, 1970 UTC.

The Date object provides uniform behavior across platforms.

The Date object supports a number of UTC (universal) methods, as well as local time methods. UTC, also known as Greenwich Mean Time (GMT), refers to the time as set by the World Time Standard. The local time is the time known to the computer where JavaScript is executed.

For compatibility with millennium calculations (in other words, to take into account the year 2000), you should always specify the year in full; for example, use 1998, not 98. To assist you in specifying the complete year, JavaScript includes the methods getFullYear, setFullYear, getUTCFullYear, and setUTCFullYear.

The following example returns the time elapsed between timeA and timeB in milliseconds.

timeA = new Date();
            // Statements here to take some action.
            timeB = new Date();
            timeDifference = timeB - timeA;

References

Date.parse|Date.UTC

Availability

JavaScript 1.0|JScript 1.0|ECMAScript v1

text_javascript aptana_docs