Date.toLocaleTimeString

toLocaleTimeString – Converts a Date object to a string.

Description

Date.toLocaleTimeString([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 – toLocaleTimeString example

The returned value will be of the primitive string type.

var date = new Date(2015, 9, 21, 16, 29, 00); console.log(date.toLocaleTimeString()); // Detects the locale automatically. console.log(date.toLocaleTimeString('en-US')); // 6:29:00 PM console.log(date.toLocaleTimeString('nb-NO')); // 18.29.00 console.log(date.toLocaleTimeString('ar-EG')); // ٦:٢٩:٠٠ م console.log(date.toLocaleTimeString('ko-KR')); // 오후 6:29:00

External references