JavaScript Date toTimeString() Method

JavaScript Date toTimeString() method returns a string representing the time portion of this date interpreted in the local timezone.

Syntax

dateObj.toTimeString()

Parameters

This method does not accept any parameter.

Return value

It returns the time portion of the given date object in English. 

Example 1: Basic Usage of Date toTimeString()

let today = new Date();

console.log(today.toTimeString());

Output

11:51:02 GMT+0530 (India Standard Time)

Example 2: Using toTimeString() with a predefined date

let specificDate = new Date('2023-08-16T12:34:56Z');

console.log(specificDate.toTimeString());

Output

18:04:56 GMT+0530 (India Standard Time)

Example 3: Extracting hours, minutes, and seconds

let now = new Date();

let timeString = now.toTimeString();
let timeParts = timeString.split(' ')[0];
let [hours, minutes, seconds] = timeParts.split(':');

console.log("Hours:", hours, "Minutes:", minutes, "Seconds:", seconds);

Output

Hours: 11 Minutes: 54 Seconds: 00

Browser Compatibility

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes

That’s it!

Related posts

JavaScript Date toUTCString()

JavaScript Date toLocaleDateString()

JavaScript Date toISOString()