X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/6746dc89c47ed01b165cc1152533605f97eb8e8d..f562e4c6e5fac7bcb445985b99acbea4d706e6f0:/docs/output/Date.js?ds=sidebyside diff --git a/docs/output/Date.js b/docs/output/Date.js new file mode 100644 index 00000000..ccba91ae --- /dev/null +++ b/docs/output/Date.js @@ -0,0 +1 @@ +Ext.data.JsonP.Date({"tagname":"class","html":"
Files
Creates Date
instances which let you work with dates and times.
If you supply no arguments, the constructor creates a Date
object for today's\ndate and time according to local time. If you supply some arguments but not\nothers, the missing arguments are set to 0. If you supply any arguments, you\nmust supply at least the year, month, and day. You can omit the hours, minutes,\nseconds, and milliseconds.
The date is measured in milliseconds since midnight 01 January, 1970 UTC. A day\nholds 86,400,000 milliseconds. The Date
object range is -100,000,000 days to\n100,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\nlocal time methods. UTC, also known as Greenwich Mean Time (GMT), refers to the\ntime as set by the World Time Standard. The local time is the time known to the\ncomputer where JavaScript is executed.
Invoking Date
in a non-constructor context (i.e., without the new
operator)\nwill return a string representing the current time.
Note that Date
objects can only be instantiated by calling Date
or using it\nas a constructor; unlike other JavaScript object types, Date
objects have no\nliteral syntax.
The following example shows several ways to assign dates:
\n\ntoday = new Date();\nbirthday = new Date(\"December 19, 1989 03:24:00\");\nbirthday = new Date(1989,11,19);\nbirthday = new Date(1989,11,17,3,24,0);\n
\n\nThe following examples show how to determine the elapsed time between two dates:
\n\n// using static methods\nvar start = Date.now();\n// the event you'd like to time goes here:\ndoSomethingForALongTime();\nvar end = Date.now();\nvar elapsed = end - start; // time in milliseconds\n\n// if you have Date objects\nvar start = new Date();\n// the event you'd like to time goes here:\ndoSomethingForALongTime();\nvar end = new Date();\nvar elapsed = end.getTime() - start.getTime(); // time in milliseconds\n\n// if you want to test a function and get back its return\nfunction printElapsedTime (fTest) {\n var nStartTime = Date.now(), vReturn = fTest(), nEndTime = Date.now();\n alert(\"Elapsed time: \" + String(nEndTime - nStartTime) + \"\n milliseconds\");\n return vReturn;\n}\n\nyourFunctionReturn = printElapsedTime(yourFunction);\n
\n\nThe following example shows how to formate a date in an ISO 8601 format using\nUTC:
\n\n// use a function for the exact format desired...\nfunction ISODateString(d){\nfunction pad(n){return n<10 ? '0'+n : n}\nreturn d.getUTCFullYear()+'-'\n + pad(d.getUTCMonth()+1)+'-'\n + pad(d.getUTCDate())+'T'\n + pad(d.getUTCHours())+':'\n + pad(d.getUTCMinutes())+':'\n + pad(d.getUTCSeconds())+'Z'}\n\nvar d = new Date();\nprint(ISODateString(d)); // prints something like 2009-09-28T19:03:12Z\n
\n\nCreates new Date object.
\nEither UNIX timestamp, date string, or year (when month and day parameters also provided):
\n\nInteger value representing the number of milliseconds since 1 January 1970\n00:00:00 UTC (Unix Epoch).
String value representing a date. The string should be in a format recognized\nby the parse method (IETF-compliant RFC 1123 timestamps).
Integer value representing the year. For compatibility (in order to avoid the\nY2K problem), you should always specify the year in full; use 1998, rather\nthan 98.
Integer value representing the month, beginning with 0 for January to 11\nfor December.
\nInteger value representing the day of the month (1-31).
\nInteger value representing the hour of the day (0-23).
\nInteger value representing the minute segment (0-59) of a time reading.
\nInteger value representing the second segment (0-59) of a time reading.
\nInteger value representing the millisecond segment (0-999) of a time reading.
\nReturns the numeric value corresponding to the current time.
\n\nThe second statement below assigns the value 25 to the variable day
, based on the value of the\nDate
object Xmas95
.
Xmas95 = new Date(\"December 25, 1995 23:15:00\")\nday = Xmas95.getDate()\n
\nValue between 1 and 31.
\nReturns the numeric value corresponding to the current time.
\n\nThe value returned by getDay
is an integer corresponding to the day of the week: 0 for Sunday, 1\nfor Monday, 2 for Tuesday, and so on.
The second statement below assigns the value 1 to weekday
, based on the value of the Date
\nobject Xmas95
. December 25, 1995, is a Monday.
Xmas95 = new Date(\"December 25, 1995 23:15:00\");\nweekday = Xmas95.getDay();\n
\nA numeric representation of the day from Sunday (0) to\nSaturday (6).
\nReturns the numeric value corresponding to the current time.
\n\nThe value returned by getFullYear
is an absolute number. For dates between the years 1000 and\n9999, getFullYear
returns a four-digit number, for example, 1995. Use this function to make sure\na year is compliant with years after 2000.
Use this method instead of the getYear
method.
The following example assigns the four-digit value of the current year to the variable yr.
\n\nvar today = new Date();\nvar yr = today.getFullYear();\n
\nFour digit representation of the year.
\nReturns the numeric value corresponding to the current time.
\n\nThe second statement below assigns the value 23 to the variable hours
, based on the value of the\nDate
object Xmas95
.
Xmas95 = new Date(\"December 25, 1995 23:15:00\")\nhours = Xmas95.getHours()\n
\nValue between 0 and 23, using 24-hour clock.
\nReturns the numeric value corresponding to the current time.
\n\nThe following example assigns the milliseconds portion of the current time to the variable ms.
\n\nvar ms;\nToday = new Date();\nms = Today.getMilliseconds();\n
\nA number between 0 and 999.
\nReturns the numeric value corresponding to the current time.
\n\nThe second statement below assigns the value 15 to the variable minutes
, based on the value of\nthe Date
object Xmas95
.
Xmas95 = new Date(\"December 25, 1995 23:15:00\")\nminutes = Xmas95.getMinutes()\n
\nValue between 0 and 59.
\nReturns the numeric value corresponding to the current time.
\n\nThe second statement below assigns the value 11 to the variable month
, based on the value of the\nDate
object Xmas95
.
Xmas95 = new Date(\"December 25, 1995 23:15:00\")\nmonth = Xmas95.getMonth()\n
\nAn integer between 0 and 11. 0 corresponds to January, 1 to February, and so on.
\nReturns the numeric value corresponding to the current time.
\n\nThe second statement below assigns the value 30 to the variable secs
, based on the value of the\nDate
object Xmas95
.
Xmas95 = new Date(\"December 25, 1995 23:15:30\")\nsecs = Xmas95.getSeconds()\n
\nValue between 0 and 59.
\nReturns the numeric value corresponding to the current time.
\n\nThe value returned by the getTime
method is the number of milliseconds since 1 January 1970\n00:00:00 UTC. You can use this method to help assign a date and time to another Date
object.
This method is functionally equivalent to the valueOf
method.
Using getTime for copying dates
\n\nConstructing a date object with the identical time value.
\n\nvar birthday = new Date(1994, 12, 10);\nvar copy = new Date();\ncopy.setTime(birthday.getTime());\n
\n\nMeasuring execution time
\n\nSubtracting two subsequent getTime calls on newly generated Date objects, give the time span\nbetween these two calls. This can be used to calculate the executing time of some operations.
\n\nvar end, start;\n\nstart = new Date();\nfor (var i = 0; i < 1000; i++)\n Math.sqrt(i);\nend = new Date();\n\nconsole.log(\"Operation took \" + (end.getTime() - start.getTime()) + \" msec\");\n
\nNumber of milliseconds since 1/1/1970 (GMT).
\nReturns the numeric value corresponding to the current time.
\n\nThe time-zone offset is the difference, in minutes, between UTC and local time. Note that this\nmeans that the offset is positive if the local timezone is behind UTC and negative if it is ahead.\nFor example, if your time zone is UTC+10 (Australian Eastern Standard Time), -600 will be returned.\nDaylight savings time prevents this value from being a constant even for a given locale
\n\nx = new Date()\ncurrentTimeZoneOffsetInHours = x.getTimezoneOffset()/60\n
\nMinutes between GMT and local time.
\nReturns the numeric value corresponding to the current time.
\n\nThe following example assigns the day portion of the current date to the variable d
.
var d;\nToday = new Date();\nd = Today.getUTCDate();\n
\nInteger between 1 and 31 representing the day.
\nReturns the numeric value corresponding to the current time.
\n\nThe following example assigns the weekday portion of the current date to the variable weekday
.
var weekday;\nToday = new Date()\nweekday = Today.getUTCDay()\n
\nA numeric representation of the day from Sunday (0) to\nSaturday (6).
\nReturns the numeric value corresponding to the current time.
\n\nThe following example assigns the four-digit value of the current year to the variable yr
.
var yr;\nToday = new Date();\nyr = Today.getUTCFullYear();\n
\nFour digit representation of the year.
\nReturns the numeric value corresponding to the current time.
\n\nThe following example assigns the hours portion of the current time to the variable hrs
.
var hrs;\nToday = new Date();\nhrs = Today.getUTCHours();\n
\nValue between 0 and 23.
\nReturns the numeric value corresponding to the current time.
\n\nThe following example assigns the milliseconds portion of the current time to the variable ms
.
var ms;\nToday = new Date();\nms = Today.getUTCMilliseconds();\n
\nMilliseconds portion of the Date.
\nReturns the numeric value corresponding to the current time.
\n\nThe following example assigns the minutes portion of the current time to the variable min
.
var min;\nToday = new Date();\nmin = Today.getUTCMinutes();\n
\nValue between 0 and 59.
\nReturns the numeric value corresponding to the current time.
\n\nThe following example assigns the month portion of the current date to the variable mon
.
var mon;\nToday = new Date();\nmon = Today.getUTCMonth();\n
\nValue between 0 (January) and 11 (December).
\nReturns the numeric value corresponding to the current time.
\n\nThe following example assigns the seconds portion of the current time to the variable sec
.
var sec;\nToday = new Date();\nsec = Today.getUTCSeconds();\n
\nValue between 0 and 59.
\nSets the day of the month (1-31) for a specified date according to local time.
\n\nIf the parameter you specify is outside of the expected range, setDate
attempts to update the\ndate information in the Date
object accordingly. For example, if you use 0 for dayValue
, the\ndate will be set to the last day of the previous month.
The second statement below changes the day for theBigDay to July 24 from its original value.
\n\ntheBigDay = new Date(\"July 27, 1962 23:30:00\")\ntheBigDay.setDate(24)\n
\nAn integer from 1 to 31, representing the day of the month.
\nNew date represented as milliseconds.
\nSets the full year (4 digits for 4-digit years) for a specified date according to\nlocal time.
\n\nIf you do not specify the monthValue
and dayValue
parameters, the values returned from the\ngetMonth
and getDate
methods are used.
If a parameter you specify is outside of the expected range, setFullYear
attempts to update the\nother parameters and the date information in the Date
object accordingly. For example, if you\nspecify 15 for monthValue, the year is incremented by 1 (year + 1), and 3 is used for the month.
theBigDay = new Date();\ntheBigDay.setFullYear(1997);
\nAn integer specifying the numeric value of the year, for example, 1995.
\nAn integer between 0 and 11 representing the months January through\nDecember.
\nAn integer between 1 and 31 representing the day of the month. If you\nspecify the dayValue
parameter, you must also specify the monthValue
.
New date represented as milliseconds.
\nSets the hours (0-23) for a specified date according to local time.
\n\nIf you do not specify the minutesValue
, secondsValue
, and msValue
parameters, the values\nreturned from the getUTCMinutes
, getUTCSeconds
, and getMilliseconds
methods are used.
If a parameter you specify is outside of the expected range, setHours attempts to update the date\ninformation in the Date
object accordingly. For example, if you use 100 for secondsValue
, the\nminutes will be incremented by 1 (min + 1), and 40 will be used for seconds.
theBigDay.setHours(7)\n
\nAn integer between 0 and 23, representing the hour.
\nAn integer between 0 and 59, representing the minutes.
\nAn integer between 0 and 59, representing the seconds. If you specify the\nsecondsValue
parameter, you must also specify the minutesValue
.
A number between 0 and 999, representing the milliseconds. If you specify the\nmsValue
parameter, you must also specify the minutesValue
and secondsValue
.
New date represented as milliseconds.
\nSets the milliseconds (0-999) for a specified date according to local time.
\n\nIf you specify a number outside the expected range, the date information in the Date
object is\nupdated accordingly. For example, if you specify 1005, the number of seconds is incremented by 1,\nand 5 is used for the milliseconds.
theBigDay = new Date();\ntheBigDay.setMilliseconds(100);\n
\nA number between 0 and 999, representing the milliseconds.
\nNew date represented as milliseconds.
\nSets the minutes (0-59) for a specified date according to local time.
\n\nIf you do not specify the secondsValue
and msValue
parameters, the values returned from\ngetSeconds
and getMilliseconds
methods are used.
If a parameter you specify is outside of the expected range, setMinutes
attempts to update the\ndate information in the Date
object accordingly. For example, if you use 100 for secondsValue
,\nthe minutes (minutesValue
) will be incremented by 1 (minutesValue + 1), and 40 will be used for\nseconds.
theBigDay.setMinutes(45)\n
\nAn integer between 0 and 59, representing the minutes.
\nAn integer between 0 and 59, representing the seconds. If you\nspecify the secondsValue parameter, you must also specify the minutesValue
.
A number between 0 and 999, representing the milliseconds. If you specify\nthe msValue
parameter, you must also specify the minutesValue
and secondsValue
.
New date represented as milliseconds.
\nSets the month (0-11) for a specified date according to local time.
\n\nIf you do not specify the dayValue
parameter, the value returned from the getDate
method is\nused.
If a parameter you specify is outside of the expected range, setMonth
attempts to update the date\ninformation in the Date
object accordingly. For example, if you use 15 for monthValue
, the year\nwill be incremented by 1 (year + 1), and 3 will be used for month.
theBigDay.setMonth(6)\n
\nAn integer between 0 and 11 (representing the months January through\nDecember).
\nAn integer from 1 to 31, representing the day of the month.
\nNew date represented as milliseconds.
\nSets the seconds (0-59) for a specified date according to local time.
\n\nIf you do not specify the msValue
parameter, the value returned from the getMilliseconds
method\nis used.
If a parameter you specify is outside of the expected range, setSeconds
attempts to update the\ndate information in the Date
object accordingly. For example, if you use 100 for secondsValue
,\nthe minutes stored in the Date
object will be incremented by 1, and 40 will be used for seconds.
theBigDay.setSeconds(30)\n
\nAn integer between 0 and 59.
\nA number between 0 and 999, representing the milliseconds. If you specify\nthemsValue
parameter, you must also specify the minutesValue
and secondsValue
.
New date represented as milliseconds.
\nSets the Date object to the time represented by a number of milliseconds since\nJanuary 1, 1970, 00:00:00 UTC, allowing for negative numbers for times prior.
\n\nUse the setTime
method to help assign a date and time to another Date
object.
theBigDay = new Date(\"July 1, 1999\")\nsameAsBigDay = new Date()\nsameAsBigDay.setTime(theBigDay.getTime())\n
\nAn integer representing the number of milliseconds since 1 January\n1970, 00:00:00 UTC.
\nNew date represented as milliseconds.
\nSets the day of the month (1-31) for a specified date according to universal time.
\n\nIf a parameter you specify is outside of the expected range, setUTCDate
attempts to update the\ndate information in the Date
object accordingly. For example, if you use 40 for dayValue
, and\nthe month stored in the Date
object is June, the day will be changed to 10 and the month will be\nincremented to July.
theBigDay = new Date();\ntheBigDay.setUTCDate(20);\n
\nAn integer from 1 to 31, representing the day of the month.
\nNew date represented as milliseconds.
\nSets the full year (4 digits for 4-digit years) for a specified date according\nto universal time.
\n\nIf you do not specify the monthValue
and dayValue
parameters, the values returned from the\ngetMonth
and getDate
methods are used.
If a parameter you specify is outside of the expected range, setUTCFullYear
attempts to update\nthe other parameters and the date information in the Date
object accordingly. For example, if you\nspecify 15 for monthValue
, the year is incremented by 1 (year + 1), and 3 is used for the month.
theBigDay = new Date();\ntheBigDay.setUTCFullYear(1997);\n
\nAn integer specifying the numeric value of the year, for example, 1995.
\nAn integer between 0 and 11 representing the months January through\nDecember.
\nAn integer between 1 and 31 representing the day of the month. If you\nspecify the dayValue
parameter, you must also specify the monthValue
.
New date represented as milliseconds.
\nSets the hour (0-23) for a specified date according to universal time.
\n\nIf you do not specify the minutesValue
, secondsValue
, and msValue
parameters, the values\nreturned from the getUTCMinutes
, getUTCSeconds
, and getUTCMilliseconds
methods are used.
If a parameter you specify is outside of the expected range, setUTCHours
attempts to update the\ndate information in the Date
object accordingly. For example, if you use 100 for secondsValue
,\nthe minutes will be incremented by 1 (min + 1), and 40 will be used for seconds.
theBigDay = new Date();\ntheBigDay.setUTCHours(8);\n
\nAn integer between 0 and 23, representing the hour.
\nAn integer between 0 and 59, representing the minutes.
\nAn integer between 0 and 59, representing the seconds. If you specify the\nsecondsValue
parameter, you must also specify the minutesValue
.
A number between 0 and 999, representing the milliseconds. If you specify the\nmsValue
parameter, you must also specify the minutesValue
and secondsValue
.
New date represented as milliseconds.
\nSets the milliseconds (0-999) for a specified date according to universal time.
\n\nIf a parameter you specify is outside of the expected range, setUTCMilliseconds
attempts to\nupdate the date information in the Date
object accordingly. For example, if you use 1100 for\nmillisecondsValue
, the seconds stored in the Date object will be incremented by 1, and 100 will\nbe used for milliseconds.
theBigDay = new Date();\ntheBigDay.setUTCMilliseconds(500);\n
\nA number between 0 and 999, representing the milliseconds.
\nNew date represented as milliseconds.
\nSets the minutes (0-59) for a specified date according to universal time.
\n\nIf you do not specify the secondsValue
and msValue
parameters, the values returned from\ngetUTCSeconds
and getUTCMilliseconds
methods are used.
If a parameter you specify is outside of the expected range, setUTCMinutes
attempts to update the\ndate information in the Date
object accordingly. For example, if you use 100 for secondsValue
,\nthe minutes (minutesValue
) will be incremented by 1 (minutesValue
+ 1), and 40 will be used for\nseconds.
theBigDay = new Date();\ntheBigDay.setUTCMinutes(43);\n
\nAn integer between 0 and 59, representing the minutes.
\nAn integer between 0 and 59, representing the seconds. If you specify the secondsValue
parameter, you must also specify the minutesValue
.
A number between 0 and 999, representing the milliseconds. If you specify the msValue
parameter, you must also specify the minutesValue
and secondsValue
.
New date represented as milliseconds.
\nSets the month (0-11) for a specified date according to universal time.
\n\nIf you do not specify the dayValue
parameter, the value returned from the getUTCDate
method is\nused.
If a parameter you specify is outside of the expected range, setUTCMonth
attempts to update the\ndate information in the Date
object accordingly. For example, if you use 15 for monthValue
, the\nyear will be incremented by 1 (year + 1), and 3 will be used for month.
theBigDay = new Date();\ntheBigDay.setUTCMonth(11);\n
\nAn integer between 0 and 11, representing the months January through\nDecember.
\nAn integer from 1 to 31, representing the day of the month.
\nNew date represented as milliseconds.
\nSets the seconds (0-59) for a specified date according to universal time.
\n\nIf you do not specify the msValue
parameter, the value returned from the getUTCMilliseconds
\nmethods is used.
If a parameter you specify is outside of the expected range, setUTCSeconds
attempts to update the\ndate information in the Date
object accordingly. For example, if you use 100 for secondsValue
,\nthe minutes stored in the Date
object will be incremented by 1, and 40 will be used for seconds.
theBigDay = new Date();\ntheBigDay.setUTCSeconds(20);\n
\nAn integer between 0 and 59.
\nA number between 0 and 999, representing the milliseconds.
\nNew date represented as milliseconds.
\nReturns the \"date\" portion of the Date as a human-readable string in American English.
\n\nDate instances refer to a specific point in time. Calling toString
will return the\ndate formatted in a human readable form in American English. In SpiderMonkey, this consists of the\ndate portion (day, month, and year) followed by the time portion (hours, minutes, seconds, and time\nzone). Sometimes it is desirable to obtain a string of the date portion; such a thing can be\naccomplished with the toDateString
method.
The toDateString
method is especially useful because compliant engines implementing ECMA-262 may\ndiffer in the string obtained from toString
for Date
objects, as the format is implementation-\ndependent and simple string slicing approaches may not produce consistent results across multiple\nengines.
var d = new Date(1993, 6, 28, 14, 39, 7);\nprintln(d.toString()); // prints Wed Jul 28 1993 14:39:07 GMT-0600 (PDT)\nprintln(d.toDateString()); // prints Wed Jul 28 1993\n
\nHuman-readable string, in local time.
\nReturns the \"date\" portion of the Date as a string, using the current locale's\nconventions.
\n\nThe toLocaleDateString
method relies on the underlying operating system in formatting dates. It\nconverts the date to a string using the formatting convention of the operating system where the\nscript is running. For example, in the United States, the month appears before the date (04/15/98),\nwhereas in Germany the date appears before the month (15.04.98). If the operating system is not\nyear-2000 compliant and does not use the full year for years before 1900 or over 2000,\ntoLocaleDateString
returns a string that is not year-2000 compliant. toLocaleDateString
behaves\nsimilarly to toString
when converting a year that the operating system does not properly format.
Methods such as getDate
, getMonth
, and getFullYear
give more portable results than\ntoLocaleDateString
. Use toLocaleDateString
when the intent is to display to the user a string\nformatted using the regional format chosen by the user. Be aware that this method, due to its\nnature, behaves differently depending on the operating system and on the user's settings.
In the following example, today
is a Date
object:
today = new Date(95,11,18,17,28,35) //months are represented by 0 to 11\ntoday.toLocaleDateString()\n
\n\nIn this example, toLocaleDateString
returns a string value that is similar to the following form.\nThe exact format depends on the platform, locale and user's settings.
12/18/95\n
\n\nYou shouldn't use this method in contexts where you rely on a particular format or locale.
\n\n\"Last visit: \" + someDate.toLocaleDateString(); // Good example\n\"Last visit was at \" + someDate.toLocaleDateString(); // Bad example\n
\nHuman-readable string that may be formatted differently depending\non the country.
\nConverts a date to a string, using the current locale's conventions. Overrides\nthe Object.toLocaleString
method.
The toLocaleString
method relies on the underlying operating system in formatting dates. It\nconverts the date to a string using the formatting convention of the operating system where the\nscript is running. For example, in the United States, the month appears before the date (04/15/98),\nwhereas in Germany the date appears before the month (15.04.98). If the operating system is not\nyear-2000 compliant and does not use the full year for years before 1900 or over 2000,\ntoLocaleString
returns a string that is not year-2000 compliant. toLocaleString
behaves\nsimilarly to toString
when converting a year that the operating system does not properly format.
Methods such as getDate
, getMonth
, getFullYear
, getHours
, getMinutes
, and getSeconds
\ngive more portable results than toLocaleString
. Use toLocaleString
when the intent is to\ndisplay to the user a string formatted using the regional format chosen by the user. Be aware that\nthis method, due to its nature, behaves differently depending on the operating system and on the\nuser's settings.
In the following example, today
is a Date
object:
today = new Date(95,11,18,17,28,35); //months are represented by 0 to 11\ntoday.toLocaleString();\n
\n\nIn this example, toLocaleString
returns a string value that is similar to the following form. The\nexact format depends on the platform, locale and user's settings.
12/18/95 17:28:35\n
\n\nYou shouldn't use this method in contexts where you rely on a particular format or locale.
\n\n\"Last visit: \" + someDate.toLocaleString(); // Good example\n\"Last visit was at \" + someDate.toLocaleString(); // Bad example\n
\nHuman-readable string that may be formatted differently depending\non the country.
\nReturns the \"time\" portion of the Date as a string, using the current locale's\nconventions.
\n\nThe toLocaleTimeString
method relies on the underlying operating system in formatting dates. It\nconverts the date to a string using the formatting convention of the operating system where the\nscript is running. For example, in the United States, the month appears before the date (04/15/98),\nwhereas in Germany the date appears before the month (15.04.98).
Methods such as getHours
, getMinutes
, and getSeconds
give more consistent results than\ntoLocaleTimeString
. Use toLocaleTimeString
when the intent is to display to the user a string\nformatted using the regional format chosen by the user. Be aware that this method, due to its\nnature, behaves differently depending on the operating system and on the user's settings.
In the following example, today
is a Date
object:
today = new Date(95,11,18,17,28,35) //months are represented by 0 to 11\ntoday.toLocaleTimeString()\n
\n\nIn this example, toLocaleTimeString
returns a string value that is similar to the following form.\nThe exact format depends on the platform.
17:28:35\n
\n\nYou shouldn't use this method in contexts where you rely on a particular format or locale.
\n\n\"Last visit: \" + someDate.toLocaleTimeString(); // Good example\n\"Last visit was at \" + someDate.toLocaleTimeString(); // Bad example\n
\nHuman-readable string that may be formatted differently depending\non the country.
\nReturns a string representing the specified Date object. Overrides the\nObject.prototype.toString
method.
The Date
object overrides the toString method of the Object object; it does not inherit\nObject.toString
. For Date
objects, the toString
method returns a string representation of the\nobject.
toString
always returns a string representation of the date in American English.
JavaScript calls the toString
method automatically when a date is to be represented as a text\nvalue or when a date is referred to in a string concatenation.
The following assigns the toString
value of a Date
object to myVar
:
x = new Date();\nmyVar=x.toString(); //assigns a value to myVar similar to:\n//Mon Sep 28 1998 14:36:22 GMT-0700 (Pacific Daylight Time)\n
\nHuman-readable string of the date in local time.
\nReturns the \"time\" portion of the Date as a human-readable string.
\n\nDate instances refer to a specific point in time. Calling toString
will return the\ndate formatted in a human readable form in American English. In SpiderMonkey, this consists of the\ndate portion (day, month, and year) followed by the time portion (hours, minutes, seconds, and\ntime zone). Sometimes it is desirable to obtain a string of the time portion; such a thing can be\naccomplished with the toTimeString
method.
The toTimeString
method is especially useful because compliant engines implementing ECMA-262 may\ndiffer in the string obtained from toString
for Date
objects, as the format is implementation-\ndependent; simple string slicing approaches may not produce consistent results across multiple\nengines.
var d = new Date(1993, 6, 28, 14, 39, 7);\nprintln(d.toString()); // prints Wed Jul 28 1993 14:39:07 GMT-0600 (PDT)\nprintln(d.toTimeString()); // prints 14:39:07 GMT-0600 (PDT)\n
\nHuman-readable string of the date in local time.
\nConverts a date to a string, using the universal time convention.
\n\nThe value returned by toUTCString
is a readable string in American English in the UTC time zone.\nThe format of the return value may vary according to the platform.
var today = new Date();\nvar UTCstring = today.toUTCString();\n// Mon, 03 Jul 2006 21:44:38 GMT\n
\nString of the date in UTC.
\nReturns the primitive value of a Date object. Overrides the\nObject.prototype.valueOf method.
\n\nThe valueOf
method returns the primitive value of a Date
object as a number data type, the\nnumber of milliseconds since midnight 01 January, 1970 UTC.
This method is functionally equivalent to the getTime
method.
This method is usually called internally by JavaScript and not explicitly in code.
\n\nx = new Date(56, 6, 17);\nmyVar = x.valueOf(); //assigns -424713600000 to myVar\n
\nDate represented as milliseconds.
\nAccepts the same parameters as the longest form of the constructor, and returns\nthe number of milliseconds in a Date
object since January 1, 1970, 00:00:00,\nuniversal time.
UTC
takes comma-delimited date parameters and returns the number of milliseconds between January\n1, 1970, 00:00:00, universal time and the time you specified.
You should specify a full year for the year; for example, 1998. If a year between 0 and 99 is\nspecified, the method converts the year to a year in the 20th century (1900 + year); for example,\nif you specify 95, the year 1995 is used.
\n\nThe UTC
method differs from the Date
constructor in two ways.\n* Date.UTC
uses universal time instead of the local time.\n* Date.UTC
returns a time value as a number instead of creating a Date
object.
If a parameter you specify is outside of the expected range, the UTC
method updates the other\nparameters to allow for your number. For example, if you use 15 for month, the year will be\nincremented by 1 (year + 1), and 3 will be used for the month.
Because UTC
is a static method of Date
, you always use it as Date.UTC()
, rather than as a\nmethod of a Date
object you created.
The following statement creates a Date
object using GMT instead of local time:
gmtDate = new Date(Date.UTC(96, 11, 1, 0, 0, 0));\n
\nA year after 1900.
\nAn integer between 0 and 11 representing the month.
\nAn integer between 1 and 31 representing the day of the month.
\nAn integer between 0 and 23 representing the hours.
\nAn integer between 0 and 59 representing the minutes.
\nAn integer between 0 and 59 representing the seconds.
\nAn integer between 0 and 999 representing the milliseconds.
\nNumber of milliseconds since January 1, 1970, 00:00:00, universal time.
\nReturns the numeric value corresponding to the current time.
\n\nThe now
method returns the milliseconds elapsed since 1 January 1970 00:00:00 UTC up until now as\na number.
When using now
to create timestamps or unique IDs, keep in mind that the resolution may be 15\nmilliseconds on Windows, so you could end up with several equal values if now
is called multiple\ntimes within a short time span.
Returns the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.
\nParses a string representation of a date, and returns the number of milliseconds\nsince January 1, 1970, 00:00:00, local time.
\n\nThe parse
method takes a date string (such as \"Dec 25, 1995\"
) and returns the number of\nmilliseconds since January 1, 1970, 00:00:00 UTC. The local time zone is used to interpret\narguments that do not contain time zone information. This function is useful for setting date\nvalues based on string values, for example in conjunction with the setTime
method and the\nDate object.
Given a string representing a time, parse returns the time value. It accepts the IETF standard (RFC\n1123 Section 5.2.14 and elsewhere) date syntax: \"Mon, 25 Dec 1995 13:30:00 GMT\"
. It understands\nthe continental US time-zone abbreviations, but for general use, use a time-zone offset, for\nexample, \"Mon, 25 Dec 1995 13:30:00 GMT+0430\"
(4 hours, 30 minutes east of the Greenwich\nmeridian). If you do not specify a time zone, the local time zone is assumed. GMT and UTC are\nconsidered equivalent.
If IPOdate
is an existing Date
object, then you can set it to August 9, 1995 (local time) as\nfollows:
IPOdate.setTime(Date.parse(\"Aug 9, 1995\"));\n
\n\nSome other examples:
\n\n// Returns 807937200000 in time zone GMT-0300, and other values in other\n// timezones, since the argument does not specify a time zone.\nDate.parse(\"Aug 9, 1995\");\n\n// Returns 807926400000 no matter the local time zone.\nDate.parse(\"Wed, 09 Aug 1995 00:00:00 GMT\");\n\n// Returns 807937200000 in timezone GMT-0300, and other values in other\n// timezones, since there is no time zone specifier in the argument.\nDate.parse(\"Wed, 09 Aug 1995 00:00:00\");\n\n// Returns 0 no matter the local time zone.\nDate.parse(\"Thu, 01 Jan 1970 00:00:00 GMT\");\n\n// Returns 14400000 in timezone GMT-0400, and other values in other\n// timezones, since there is no time zone specifier in the argument.\nDate.parse(\"Thu, 01 Jan 1970 00:00:00\");\n\n// Returns 14400000 no matter the local time zone.\nDate.parse(\"Thu, 01 Jan 1970 00:00:00 GMT-0400\");\n
\nA string representing a date.
\nNumber of milliseconds since January 1, 1970, 00:00:00, local time.
\n