Date Object
An object that enables basic storage and retrieval of dates and times. There are two forms of the Date constructor.
function Date( [dateVal : { Number | String | System.DateTime } ] )
function Date( year : int, month : int, date : int[, hours : int [, minutes : int [, seconds : int [, ms : int]]]] )
Arguments
dateVal
Optional. If a numeric value, dateVal represents the number of milliseconds in Coordinated Universal Time between the specified date and midnight January 1, 1970. If a string, dateVal is parsed according to the rules in the parse method. The dateVal can also be a .NET date value.year
Required. The full year, for example, 1976 (not 76).month
Required. The month as an integer between 0 and 11 (January to December).date
Required. The date as an integer between 1 and 31.hours
Optional. Must be supplied if minutes is supplied. An integer from 0 to 23 (midnight to 11pm) that specifies the hour.minutes
Optional. Must be supplied if seconds is supplied. An integer from 0 to 59 that specifies the minutes.seconds
Optional. Must be supplied if milliseconds is supplied. An integer from 0 to 59 that specifies the seconds.ms
Optional. An integer from 0 to 999 that specifies the milliseconds.
Remarks
A Date object contains a number representing a particular instance in time to within a millisecond. If the value of an argument is greater than its range or is a negative number, other stored values are modified accordingly. For example, if you specify 150 seconds, JScript redefines that number as two minutes and 30 seconds.
If the number is NaN, the object does not represent a specific instance in time. If you pass no parameters to the Date constructor, it is initialized to the current time (UTC). A variable of type Date must be initialized before you can use it.
The range of dates that can be represented in a Date object is approximately 285,616 years on either side of January 1, 1970.
The Date object has two static methods, parse and UTC, that are called without creating a Date object.
If the Date constructor is called without the new operator, the Date object that is returned contains the current date regardless of the arguments passed to the constructor.
Note
The Date object interoperates with the .NET Framework System.DateTime data type within JScript. However, other Common Language Specification (CLS) languages cannot use the Date object because only JScript provides the object; it is not derived from a .NET Framework type. Consequently, when type-annotating the parameters and return types of CLS-compliant methods, make sure to use the System.DateTime data type instead of the Date object. However, you may use the Date object to type annotate identifiers other than the parameters or return types. For more information, see Writing CLS-Compliant Code.
Example
The following example uses the Date object.
var s : String = "Today's date is: "; // Declare variables.
var d : Date = new Date(); // Create Date object with today's date.
s += (d.getMonth() + 1) + "/"; // Get month
s += d.getDate() + "/"; // Get day
s += d.getYear(); // Get year.
print(s); // Print date.
If this program were run on January 26, 1992, the output would have been:
Today's date is: 1/26/1992
Properties and Methods
Date Object Properties and Methods