Previous PageNext Page

7.11 Date Object

The Date object enables basic storage and retrieval of dates and times.
 

Methods

getDate
 
Returns the day of the month according to local time.
 
getDay
 
Returns the day of the week according to local time.
 
getFullYear
 
Returns the 4-digit year according to local time.
 
getHours
 
Returns the hours according to local time.
 
getMilliseconds
 
Returns the number of milliseconds past the second according to local time.
 
getMinutes
 
Returns the number of minutes past the hour according to local time.
 
getMonth
 
Returns the month value according to local time.
 
getSeconds
 
Returns the number of seconds past the minute according to local time.
 
getTime
 
Returns the time stored in a Date object.
 
getTimezoneOffset
 
Determines the difference in minutes between the time on the host computer and Universal Coordinated Time (UTC).
 
getUTCDate
 
Returns the date of the month according to UTC.
 
getUTCDay
 
Returns the day of the week according to UTC.
 
getUTCFullYear
 
Returns the 4-digit year according to UTC.
 
getUTCHours
 
Returns the hours according to UTC.
 
getUTCMilliseconds
 
Returns the number of milliseconds past the second according to UTC.
 
getUTCMinutes
 
Returns the number minutes past the hour according to UTC.
 
getUTCMonth
 
Returns the month according to UTC.
 
getUTCSeconds
 
Returns the number of seconds past the minute according to UTC.
 
getVarDate
 
Returns the VT_DATE value.
 
getYear
 
Returns the 2-digit year.
 
parse
 
Parses a string containing a date and returns the number of milliseconds between that date and midnight, January 1, 1970.
 
setDate
 
Sets the numeric data according to local time.
 
setFullYear
 
Sets the 4-digit year according to local time.
 
setHours
 
Modifies the hours value according to local time.
 
setMilliseconds
 
Modifies the milliseconds value according to local time.
 
setMinutes
 
Modifies the minutes value according to local time.
 
setMonth
 
Modifies the month according to local time.
 
setSeconds
 
Modifies the seconds according to local time.
 
setTime
 
Sets the date and time value directly.
 
setUTCDate
 
Sets the numeric date in Universal Coordinated Time (UTC)
 
setUTCFullYear
 
Sets the year value according to UTC.
 
setUTCHours
 
Modifies the year value according to UTC.
 
setUTCMilliseconds
 
Modifies the milliseconds according to UTC.
 
setUTCMinutes
 
Modifies the minutes according to UTC.
 
setUTCMonth
 
Modifies the month according to UTC.
 
setUTCSeconds
 
Modifies the seconds according to UTC.
 
setYear
 
Sets the 2-digit year.
 
toGMTString
 
Converts the date to a string using GMT conventions.
 
toLocaleString
 
Converts the date to a string using the current locale.
 
toUTCString
 
Converts the date to a string using UTC conventions.
 
UTC
 
Computes the number of milliseconds between midnight, January 1, 1970 Universal Coordinated Time (or GMT) and the supplied date.
 

Syntax

var newDateObj = new Date()

var newDateObj = new Date(dateVal)

var newDateObj = new Date(year, month, date[, hours[, minutes[, seconds[,ms]]]])

dateVal
If a numeric value, 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
The full year, for example, 1976 (and not 76). Required.
month
The month as an integer between 0 and 11 (January to December).
date
An integer between 1 and 31. Required.
hours
Must be supplied if minutes is supplied. An integer from 0 to 23 (midnight to 11pm) that specifies the hour. Optional.
minutes
Must be supplied if seconds is supplied. An integer from 0 to 59 that specifies the minutes. Optional.
seconds
Must be supplied if milliseconds is supplied. An integer from 0 to 59 that specifies the seconds. Optional.
ms
An integer from 0 to 999 that specifies the milliseconds. Optional.

Remarks

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, that indicates that 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 the parse and UTC methods.
 

Copyright © 2000 Chili!Soft

Previous PageTop Of PageNext Page