Core JavaScript 1.5 Reference:Global Objects:Date:toLocaleTimeString
From MDC
Contents |
[edit] Summary
Converts a date to a string, returning the "date" portion using the current locale's conventions.
| Method of Date | |
| Implemented in: | JavaScript 1.0, NES 2.0 |
| ECMA Version: | ECMA-262 |
[edit] Syntax
toLocaleTimeString()
[edit] Parameters
None.
[edit] Description
The toLocaleTimeString method relies on the underlying operating system in formatting dates. It converts the date to a string using the formatting convention of the operating system where the script is running. For example, in the United States, the month appears before the date (04/15/98), whereas in Germany the date appears before the month (15.04.98). If the operating system is not year-2000 compliant and does not use the full year for years before 1900 or over 2000, toLocaleTimeString returns a string that is not year-2000 compliant. toLocaleTimeString behaves similarly to toString when converting a year that the operating system does not properly format.
Methods such as getHours, getMinutes, and getSeconds give more consistent results than toLocaleTimeString. Use toLocaleTimeString when then intent is to display to the user a string formatted using the regional format of chosen by the user. Be aware that this method, due to its nature, behaves differently depending on the operating system and on the user's settings.
[edit] Examples
[edit] Using toLocaleTimeString
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 today.toLocaleTimeString()
In this example, toLocaleTimeString returns a string value that is similar to the following form. The exact format depends on the platform.
17:28:35