Core object | |
Implemented in |
Navigator 2.0, LiveWire 1.0 Navigator 3.0: added prototype property
|
Date
constructor:new Date()
new Date("month day, year hours:minutes:seconds")
new Date(yr_num, mo_num, day_num)
new Date(yr_num, mo_num, day_num, hr_num, min_num, sec_num)
Date
object for today's date and 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, and seconds.The way JavaScript handles dates is very similar to the way Java handles dates: both languages have many of the same date methods, and both store dates internally as the number of milliseconds since January 1, 1970 00:00:00. Dates prior to 1970 are not allowed.
|
Allows the addition of properties to a Date object.
|
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)
Function.prototype
.
Property of |
Date
|
Implemented in | Navigator 3.0, LiveWire 1.0 |
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
getDate()
getDate
is an integer between 1 and 31.day
, based on the value of the Date
object Xmas95
.Xmas95 = new Date("December 25, 1995 23:15:00")
day = Xmas95.getDate()
Date.setDate
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
getDay()
getDay
is an integer corresponding to the day of the week: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on.weekday
, based on the value of the Date
object Xmas95
. December 25, 1995, is a Monday.Xmas95 = new Date("December 25, 1995 23:15:00")
weekday = Xmas95.getDay()
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
getHours()
getHours
is an integer between 0 and 23.hours
, based on the value of the Date
object Xmas95
.Xmas95 = new Date("December 25, 1995 23:15:00")
hours = Xmas95.getHours()
Date.setHours
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
getMinutes()
getMinutes
is an integer between 0 and 59.minutes
, based on the value of the Date
object Xmas95
.Xmas95 = new Date("December 25, 1995 23:15:00")
minutes = Xmas95.getMinutes()
Date.setMinutes
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
getMonth()
getMonth
is an integer between 0 and 11. 0 corresponds to January, 1 to February, and so on.month
, based on the value of the Date
object Xmas95
.Xmas95 = new Date("December 25, 1995 23:15:00")
month = Xmas95.getMonth()
Date.setMonth
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
getSeconds()
getSeconds
is an integer between 0 and 59.secs
, based on the value of the Date
object Xmas95
.Xmas95 = new Date("December 25, 1995 23:15:30")
secs = Xmas95.getSeconds()
Date.setSeconds
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
getTime()
getTime
method is the number of milliseconds since 1 January 1970 00:00:00. You can use this method to help assign a date and time to another Date
object.theBigDay
to sameAsBigDay
:theBigDay = new Date("July 1, 1999")
sameAsBigDay = new Date()
sameAsBigDay.setTime(theBigDay.getTime())
Date.setTime
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
getTimezoneOffset()
x = new Date()
currentTimeZoneOffsetInHours = x.getTimezoneOffset()/60
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
getYear()
getYear
method returns either a 2-digit or 4-digit year:getYear
is the year minus 1900. For example, if the year is 1976, the value returned is 76.getYear
is the four-digit year. For example, if the year is 1856, the value returned is 1856. If the year is 2026, the value returned is 2026.year
.Xmas = new Date("December 25, 1995 23:15:00")Example 2. The second statement assigns the value 2000 to the variable
year = Xmas.getYear()
year
.Xmas = new Date("December 25, 2000 23:15:00")Example 3. The second statement assigns the value 95 to the variable
year = Xmas.getYear()
year
, representing the year 1995.Xmas.setYear(95)
year = Xmas.getYear()
Date.setYear
Method of |
Date
|
Static | |
Implemented in | Navigator 2.0, LiveWire 1.0 |
Date.parse(dateString)
dateString | A string representing a date. |
parse
method takes a date string (such as "Dec 25, 1995"
) and returns the number of milliseconds since January 1, 1970, 00:00:00 (local time). This function is useful for setting date values based on string values, for example in conjunction with the setTime
method and the Date
object.IPOdate
is an existing Date
object, then you can set it to August 9, 1995 as follows:IPOdate.setTime(Date.parse("Aug 9, 1995"))
Date.UTC
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
setDate(dayValue)
dayValue | An integer from 1 to 31, representing the day of the month. |
theBigDay
to July 24 from its original value.theBigDay = new Date("July 27, 1962 23:30:00")
theBigDay.setDate(24)
Date.getDate
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
setHours(hoursValue)
hoursValue | An integer between 0 and 23, representing the hour. |
theBigDay.setHours(7)
Date.getHours
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
setMinutes(minutesValue)
minutesValue | An integer between 0 and 59, representing the minutes. |
theBigDay.setMinutes(45)
Date.getMinutes
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
setMonth(monthValue)
monthValue | An integer between 0 and 11 (representing the months January through December). |
theBigDay.setMonth(6)
Date.getMonth
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
setSeconds(secondsValue)
secondsValue | An integer between 0 and 59. |
theBigDay.setSeconds(30)
Date.getSeconds
Date
object.
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
setTime(timevalue)
timevalue | An integer representing the number of milliseconds since 1 January 1970 00:00:00. |
setTime
method to help assign a date and time to another Date
object.theBigDay = new Date("July 1, 1999")
sameAsBigDay = new Date()
sameAsBigDay.setTime(theBigDay.getTime())
Date.getTime
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
setYear(yearValue)
yearValue | An integer. |
yearValue
is a number between 0 and 99 (inclusive), then the year for dateObjectName
is set to 1900 + yearValue
. Otherwise, the year for dateObjectName
is set to yearValue
.Example 1. The year is set to 1996.
theBigDay.setYear(96)Example 2. The year is set to 1996.
theBigDay.setYear(1996)Example 3. The year is set to 2000.
theBigDay.setYear(2000)
Date.getYear
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
toGMTString()
toGMTString
varies according to the platform.today
is a Date
object:today.toGMTString()In this example, the
toGMTString
method converts the date to GMT (UTC) using the operating system's time-zone offset and returns a string value that is similar to the following form. The exact format depends on the platform.Mon, 18 Dec 1995 17:28:35 GMT
Date.toLocaleString
Method of |
Date
|
Implemented in | Navigator 2.0, LiveWire 1.0 |
toLocaleString()
toLocaleString
, be aware that different platforms assemble the string in different ways. Using methods such as getHours
, getMinutes
, and getSeconds
gives more portable results.today
is a Date
object:today = new Date(95,11,18,17,28,35) //months are represented by 0 to 11In this example,
today.toLocaleString()
toLocaleString
returns a string value that is similar to the following form. The exact format depends on the platform. 12/18/95 17:28:35
Date.toGMTString
Date
object since January 1, 1970, 00:00:00, Universal Coordinated Time (GMT).
Method of |
Date
|
Static | |
Implemented in | Navigator 2.0, LiveWire 1.0 |
Date.UTC(year, month, day, hrs, min, sec)
UTC
takes comma-delimited date parameters and returns the number of milliseconds since January 1, 1970, 00:00:00, Universal Coordinated Time (GMT).
Because UTC is a static method of Date
, you always use it as Date.UTC()
, rather than as a method of a Date
object you created.
Date
object using GMT instead of local time:gmtDate = new Date(Date.UTC(96, 11, 1, 0, 0, 0))
Date.parse
Last Updated: 10/31/97 16:00:33