The Date.parse() page offers more examples about these non-standard cases. Implementations behave inconsistently in this case. A string may have in-bounds date components (with the bounds defined above), but does not represent a date in reality (for example, "February 30"). Implementations are not required to return invalid date for out-of-bounds date components, although they usually do. Non-standard strings can be parsed in any way as desired by the implementation, including the time zone - most implementations use the local time zone by default. A library can help if many different formats are to be accommodated. Always conduct cross-browser tests to ensure your code works in all target browsers. However, there are some formats that are supported in all major implementations - like RFC 2822 format - in which case their usage can be acceptable. Note: You are encouraged to make sure your input conforms to the date time string format above for maximum compatibility, because support for other formats is not guaranteed. The toISOString() method returns a string representation of the date in the date time string format, with the time zone offset always set to Z (UTC). Furthermore, implementations are allowed to support other date formats when the input fails to match this format. See Broken Parser – A Web Reality Issue.ĭate.parse() and the Date() constructor both accept strings in the date time string format as input. This is due to a historical spec error that was not consistent with ISO 8601 but could not be changed due to web compatibility. When the time zone offset is absent, date-only forms are interpreted as a UTC time and date-time forms are interpreted as local time. Each combination can be followed by a time zone offset.įor example, "" ( date-only form), "T14:48:00" ( date-time form), or "T14:48:00.000+09:00" ( date-time form with milliseconds and time zone) are all valid date time strings. Date-time form: one of the above date-only forms, followed by T, followed by HH:mm, HH:mm:ss, or HH:mm:ss.sss. Date-only form: YYYY, YYYY-MM, YYYY-MM-DD.Various components can be omitted, so the following are all valid: Z is the timezone offset, which can either be the literal character Z (indicating UTC), or + or - followed by HH:mm, the offset in hours and minutes from UTC.sss is the millisecond, with three digits ( 000 to 999).ss is the second, with two digits ( 00 to 59).mm is the minute, with two digits ( 00 to 59).As a special case, 24:00:00 is allowed, and is interpreted as midnight at the beginning of the next day. HH is the hour, with two digits ( 00 to 23).The T is required when specifying the time part. T is a literal character, which indicates the beginning of the time part of the string.DD is the day of the month, with two digits ( 01 to 31).MM is the month, with two digits ( 01 to 12).000000 is explicitly disallowed as a valid year. YYYY is the year, with four digits ( 0000 to 9999), or as an expanded year of + or - followed by six digits.The format is as follows: YYYY-MM-DDTHH:mm:ss.sssZ The JavaScript specification only specifies one format to be universally supported: the date time string format, a simplification of the ISO 8601 calendar date extended format. There are many ways to format a date as a string. Date.UTC() works similarly, but it interprets the components as UTC time and also accepts a single argument representing the year. The Date() constructor can be called with two or more arguments, in which case they are interpreted as the year, month, day, hour, minute, second, and millisecond, respectively, in local time. There are two groups of Date methods: one group gets and sets various date components by interpreting the timestamp as a local time, while the other uses UTC. In essence, the timezone offset is the offset from UTC time, at the time represented by the Date object and at the location of the host environment. Note that the timezone offset does not only depend on the current timezone, but also on the time represented by the Date object, because of daylight saving time and historical changes. The getTimezoneOffset() method returns the difference between UTC and the local time in minutes.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |