Converts a date to a string, using the current locale's conventions.
Method of Date
Syntax
toLocaleString()
Parameters
None
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 Date.getHours, Date.getMinutes, and Date.getSeconds give more portable results than toLocaleString.
Examples
In the following example, today is a Date object:
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