JavaScript » Date » toLocaleString

Syntax:
object.toLocaleString( )

This method uses the relevant locale's date conventions when converting a date to a string.

This method uses the relevant locale's date conventions when converting a date to a string. This is done by using the default date format of the user's operating system. This takes in to account the differences between date formatting methods used in different countries, e.g. in the U.K. the date comes before the month as opposed to the U.S. convention of the month first.

Examples

Code:
myDate = new Date(99, 04, 23)
document.write(myDate.toLocaleString())
Output:
23/05/1999 00:00:00
Explanation:

This code uses the toLocaleString method to convert the date set in the myDate object to a string. For the purposes of this example, the locale of the operating system is set to that of the United Kingdom.