Get the Hours and Minutes from a Date in JavaScript

avatar

Borislav Hadzhiev

Last updated: Jul 25, 2022

banner

Check out my new book

Get the Hours and Minutes from a Date #

To get the hours and minutes from a date, call the getHours() and getMinutes() methods on the date object. The getHours method returns the hours and the getMinutes() method returns the minutes in the specified date.

index.js
// 👇️ from CURRENT DATE const now = new Date(); const current = now.getHours() + ':' + now.getMinutes(); console.log(current); // 👉️ 13:27 // 👇️ from another DATE const date = new Date('December 14, 2026 08:33:00'); const hoursAndMinutes = date.getHours() + ':' + date.getMinutes(); console.log(hoursAndMinutes); // 👉️ 8:33 // 👇️ With PM / AM const withPmAm = now.toLocaleTimeString('en-US', { // en-US can be set to 'default' to use user's browser settings hour: '2-digit', minute: '2-digit', }); console.log(withPmAm); // 👉️ 01:27 PM

We used the Date.getHours and Date.getMinutes methods to get the hours and minutes for a specific date.

Note that the results from the functions might sometimes return a single digit (if the hours or minutes are less than 10). If you need consistently get 2 digits output, pad the hours and minutes if necessary.
index.js
function padTo2Digits(num) { return String(num).padStart(2, '0'); } const date = new Date('December 14, 2026 08:09:00'); const hoursAndMinutes = padTo2Digits(date.getHours()) + ':' + padTo2Digits(date.getMinutes()); console.log(hoursAndMinutes); // 👉️ 08:09

We used the String.padStart method to add a leading zero to the hours and minutes if necessary.

The first parameter we passed to the padStart method is the total length of the string, and the second is the pad string.

We set the total length to 2 characters, so the padStart method won't pad the hours and minutes if their values are greater than 10.

In our next example, we used the toLocaleTimeString method to get a locale specific representation of the hours and minutes.

We passed en-US for the locale and got the hours and minutes formatted as HH:MM PM/AM.

You can also pass default for the locale, which would use the user's browser configuration.

index.js
const def = now.toLocaleTimeString('default', { hour: '2-digit', minute: '2-digit', }); console.log(def); // 👉️ 01:46 PM

The second parameter we passed to the method is an options object. We set both the hour and minute properties to 2-digit.

This means that even if the hours and minutes are less than 10, a leading 0 would automatically get added to make the output consistent.

Similarly, you could use a different locale to get a different output format.

index.js
const enUS = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', }); console.log(enUS); // 👉️ 01:47 PM const enGB = now.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', }); console.log(enGB); // 👉️ 13:47 const deDE = now.toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit', }); console.log(deDE); // 👉️ 13:47

The output from the toLocaleTimeString is always going to display 2 digits for the hours and minutes, so we don't have to add a leading zero if their values are less than 10.

Further Reading #

Use the search field on my Home Page to filter through my more than 3,000 articles.