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

toLocaleDateString Method (Date) (JavaScript)

Returns a date as a string value that is appropriate to the host environment's current locale or the specified locale.

dateObj.toLocaleDateString( [locales][, options]) 
dateObj

Required. A Date object.

locales

Optional. An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.

options

Optional. An object that contains one or more properties that specify comparison options.

Starting in Internet Explorer 11, toLocaleDateString uses Intl.DateTimeFormat internally to format the date, which adds support for the locales and options parameters. For more information about these parameters, see Intl.DateTimeFormat.

Important note Important

The locales and options parameters are not supported in all document modes and browser versions. For more information, see the Requirements section.

When you use toLocaleDateString in Internet Explorer 10 standards document mode, earlier document modes, and quirks mode:

  • it returns a string value that contains a date in the current time zone.

  • The returned date is in the default format of the host environment's current locale.

If you omit the locales parameter, the return value of this method cannot be relied upon in scripting, because it will vary from computer to computer. In this scenario, use the method only to format displayed text – never as part of a computation.

The following example shows how to use the toLocaleDateString method with a specified locale and comparison options.

var date = new Date(Date.UTC(2013, 1, 1, 14, 0, 0));
var options = { weekday: "long", year: "numeric", month: "short",
    day: "numeric" };

// Using I18N toLocaleString
document.write(date.toLocaleDateString("en-US"));
document.write(date.toLocaleDateString("ja-JP"));
document.write(date.toLocaleDateString("ar-SA", options));
document.write(date.toLocaleDateString("hi-IN", options));

// Output:
// ‎2‎/‎1‎/‎2013‎ 
// ‎2013‎年‎2‎月‎1‎日‎
// ‏الجمعة‏, ‏٢٠‏ ‏ربيع الأول‏, ‏١٤٣٤
// ‎शुक्रवार‎, ‎01‎ ‎फरवरी‎ ‎2013

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

locales and options parameters:

Supported in the Internet Explorer 11 standards document mode. Also supported in Store apps (Windows 8.1 and Windows Phone 8.1). See Version Information. Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards. Not supported in Windows 8.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.