Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Scripting
 Date Object (JScript 5.6)
This page is specific to
.NET Framework 3.0

Other versions are also available for the following:
JScript
Date Object (JScript 5.6)

Updated: November 2007

Enables basic storage and retrieval of dates and times.

dateObj = new Date()
dateObj = new Date(dateVal)
dateObj = new Date(year, month, date[, hours[, minutes[, seconds[,ms]]]]) 
dateObj

Required. The variable name to which the Date object is assigned.

dateVal

Required. If a numeric value, dateVal represents the number of milliseconds in Universal Coordinated 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 argument can also be a VT_DATE value as returned from some ActiveX® objects.

year

Required. The full year, for example, 1976 (and 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.

A Date object contains a number representing a particular instant 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 instant of time. If you pass no parameters to the Date object, it is initialized to the current time (UTC). A value must be given to the object 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 that are called without creating a Date object. They are parse and UTC.

The following example illustrates the use of the Date object.

function DateDemo(){
   var d, s = "Today's date is: ";           //Declare variables.
   d = new Date();                           //Create Date object.
   s += (d.getMonth() + 1) + "/";            //Get month
   s += d.getDate() + "/";                   //Get day
   s += d.getYear();                         //Get year.
   return(s);                                //Return date.
}
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker