Date.toLocaleString

toLocaleString – Converts a Date object to a string.

Description

Date.toLocaleString([mixed locales, [object options]])

Parameters

Name Description Type Default Optional
locales A string or array containing strings for the preferred locale format. mixed Yes
options See options below. object Yes
Options parameter

The options parameter may contain one or more of the following data items.

localeMatcher

Possible values are: "best fit" (default) or "lookup".

timeZone

The time zone to use.

hour12

Possible values are: true or false. Default is set to the locale standard value.

formatMatcher

Possible values are: "best fit" (default) or "basic".

weekday

Possible values are "narrow", "short" or "long".

era

Possible values are "narrow", "short" or "long".

year

Possible values are "numeric" or "2-digit".

month

Possible values are "numeric", "2-digit", "narrow", "short" or "long".

day

Possible values are "numeric" or "2-digit".

hour

Possible values are "numeric" or "2-digit".

minute

Possible values are "numeric" or "2-digit"

second

Possible values are "numeric" or "2-digit"

timeZoneName

Possible values are "short" or "long".

Return values

string primitive.

Examples

Example #1 – toLocaleString example

The returned value will be of the primitive string type.

var date = new Date(2015, 9, 21, 16, 29, 00); console.log(date.toLocaleString()); // Detects the locale automatically. console.log(date.toLocaleString('en-US')); // 10/21/2015, 4:29:00 PM console.log(date.toLocaleString('nb-NO')); // 21.10.2015, 16.29.00 console.log(date.toLocaleString('ar-EG')); // ٢١‏/١٠‏/٢٠١٥ ٤:٢٩:٠٠ م console.log(date.toLocaleString('ko-KR')); // 2015. 10. 21. 오후 4:29:00

External references