JavaScript toLocaleTimeString

The JavaScript toLocaleTimeString function converts the Time portion of a given date and time to a string using the system locale language conversion. 

The syntax of the toLocaleTimeString function is:

 Date.toLocaleTimeString(locale, options)

Parameters: It accepts two optional parameters.

  • locale: Specify the language that the JavaScript toLocaleTimeString function has to consider to convert the time portion to a string. For example, en-GB.
  • options: Here, we can specify how the hour, minute, second, and day period should appear. For example, hour12: false.

Return Value: The toLocaleTimeString method returns the string representation of the time portion of the given datetime according to the specified language.

JavaScript toLocaleTimeString example

In the following example, we use the toLocaleTimeString method without any parameter values. It means the function uses the system locale language to convert the time portion of today’s datetime to a string.

const dt = new Date();
console.log(dt);
console.log(dt.toLocaleTimeString());
Tue Jun 16 2026 15:42:45 GMT+0530 (India Standard Time) 
3:42:45 pm

If you notice the output, instead of showing 15:42:45 as the time, it returns 3:42:45 pm. It follows the current local system settings. Please refer to the toLocaleDateString() for dates.

Example 2: In this JavaScript example, we use the Date() constructor to parse a custom date. Next, the toLocaleTimeString method returns the time portion of the custom date and time in a string format.

const dt = new Date(2022, 11, 31, 22, 45, 32);
console.log(dt);
console.log(dt.toLocaleTimeString());
Sat Dec 31 2022 22:45:32 GMT+0530 (India Standard Time) 
10:45:32 pm

Using locale in the JavaScript toLocaleTimeString method

By default, the toLocaleTimeString function uses the local language to convert time to a string. However, we can specify the language it must use for the time conversion. Here, we mentioned the English of Great Britain, so it shows time as 15:47:57.

const dt = new Date();
console.log(dt);
console.log(dt.toLocaleTimeString("en-GB"));
Tue Jun 16 2026 15:47:57 GMT+0530 (India Standard Time) 
15:47:57

Using options in the toLocaleTimeString method

The toLocaleTimeString function has options to mention how the time should look. For instance, US English shows dates in AM and PM format., However, if we set the hours12 option to false, it returns in 24-hour format.

const dt = new Date();
console.log(dt);
console.log(dt.toLocaleTimeString("en-US"));
console.log(dt.toLocaleTimeString("en-US", {hour12:false}));
Tue Jun 16 2026 15:49:28 GMT+0530 (India Standard Time) 
3:49:28 PM 
15:49:28

JavaScript toLocaleTimeString 24 hours format

Use the options parameter and set hours12 to false, and it returns the time in 24-hour format. The alternative approach is using the locale as English of Great Britain.

const dt = new Date();
console.log(dt);
console.log(dt.toLocaleTimeString("en-GB"));
console.log(dt.toLocaleTimeString("en-US", {hour12:false}));
Tue Jun 16 2026 15:54:06 GMT+0530 (India Standard Time) 
15:54:06 
15:54:06