Core JavaScript 1.5 Reference:Global Objects:Date:toLocaleDateString
From MDC
Contents |
[edit] Summary
Converts a date to a string, returning the "date" portion 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
toLocaleDateString()
[edit] Parameters
None.
[edit] Description
The toLocaleDateString 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, toLocaleDateString returns a string that is not year-2000 compliant. toLocaleDateString 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 toLocaleDateString.
[edit] Examples
[edit] Example: Using toLocaleDateString
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.toLocaleDateString()
In this example, toLocaleDateString returns a string value that is similar to the following form. The exact format depends on the platform.
12/18/95