Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

toLocaleString Method (JavaScript)

Returns a date converted to a string using the current locale.

dateObj.toLocaleString() 

The required dateObj is any Date object.

The toLocaleString method returns a String object that contains the date written in the current locale's long default format.

  • For dates between 1601 and 1999 A.D., the date is formatted according to the user's Control Panel Regional Settings.

  • For dates outside this range, the default format of the toString method is used.

For example, in the United States, toLocaleString returns "01/05/96 00:00:00" for January 5. In Europe, it returns "05/01/96 00:00:00" for the same date, as European convention puts the day before the month.

NoteNote

toLocaleString should only be used to display results to a user; it should never be used as the basis for computation within a script as the returned result is machine-specific.

The following example illustrates the use of the toLocaleString method.

function toLocaleStrDemo(){   
   var d, s;                      //Declare variables.
   d = new Date();                //Create Date object.
   s = "Current setting is ";
   s += d.toLocaleString();       //Convert to current locale.
   return(s);                     //Return converted date
}

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.

Applies To: Array Object (JavaScript)| Date Object (JavaScript)| Number Object (JavaScript)| Object Object (JavaScript)

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft. All rights reserved.