JavaScript tutorial:
toLocaleString method

 

Applies to: Date Object

The toLocaleString method is use to converted a date to a string using the current locale.

Syntax

dateObj.toLocaleString( )

Return

Returns a string using the current locale format.

Example

The toLocaleString method returns a String object that contains the date written in the current locale's default format. The format of the return value depends on the current locale. For example, in the United States, toLocaleString may return "01/05/96 00:00:00" for January 5, but in Europe, it may return "05/01/96 00:00:00" for the same date, as European convention puts the day before the month.

The following example illustrates the use of the toLocaleString method:

d = new Date();
s = "Current setting is ";
s += d.toLocaleString();
document.write(s)

To run the code above, paste it into JavaScript Editor, and click the Execute button

See also: Date Object Methods