Core JavaScript 1.5 Reference:Global Objects:Date:toLocaleString
From MDC
Contents |
[edit] Summary
Converts a date to a string, using the operating system's locale's conventions.
| Method of Date | |
| Implemented in: | JavaScript 1.0, NES 2.0 |
| ECMA Version: | ECMA-262 |
[edit] Syntax
toLocaleString()
[edit] Parameters
None.
[edit] Description
The toLocaleString 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, toLocaleString returns a string that is not year-2000 compliant. toLocaleString 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 portable results than toLocaleString.
[edit] Examples
[edit] Using toLocaleString
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.toLocaleString();
In this example, 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