Converts a date to a string, using the operating system's locale's conventions.
|ECMAScript Edition||ECMAScript 1st Edition|
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
getSeconds give more portable results than
toLocaleString when the intent is to display to the user a string formatted using the regional format 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.
In the following example,
today is a
var 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, locale and user's settings.
You shouldn't use this method in contexts where you rely on a particular format or locale.
"Last visit: " + someDate.toLocaleString(); // Good example "Last visit was at " + someDate.toLocaleString(); // Bad example
|Feature||Chrome||Firefox (Gecko)||Internet Explorer||Opera||Safari (WebKit)|
|Feature||Android||Firefox Mobile (Gecko)||IE Phone||Opera Mobile||Safari Mobile|