Date.prototype.getMinutes()
Return the minutes past the hour for a date according to local time.
getMinutes()- Added in JavaScript ES1
Return value
numberAn integer between 0 and 59 representing the minutes for the given date according to local time. Returns NaN if the date is invalid.
Errors
Throws a TypeError if called on a value that is not a Date object.
Returns the minutes past the hour, 0 through 59, in local time. It is the middle field of a clock reading and is almost always used alongside getHours().
When to reach for it
Use it when formatting a time by hand, snapping a timestamp to a 5-, 15- or 30-minute slot for a booking grid, or checking that a scheduled job fires on the right minute.
What trips people up
Padding. The value is a number, so 9:05 comes back as 5 and naive concatenation renders it as "9:5". Wrap it with String(m).padStart(2, "0"). This is the single most common bug on this method.
Minutes are not always a whole-hour offset from UTC. India, Iran, Nepal, parts of Australia and the Chatham Islands run on 30- or 45-minute offsets, so getMinutes() and getUTCMinutes() can legitimately differ. Code that assumes the two always match will produce wrong times for a real slice of users.
For a rounded or snapped time, remember that changing the minutes alone leaves the seconds and milliseconds intact — a bucket boundary usually wants setSeconds(0, 0) too, or the comparison against another timestamp will be off by a fraction of a minute.
To display a time for a user, Intl.DateTimeFormat handles padding and locale conventions for you.
Example
When to use it
- Format a timestamp as HH:MM without a date library
- Snap a booking time down to the nearest 15-minute slot
- Verify a cron-style job is firing on the expected minute
- Compute minutes elapsed within the current hour
Frequently asked questions
How do I format minutes with a leading zero?
Use String(date.getMinutes()).padStart(2, "0"), since the method returns a number and 5 would otherwise render as "5". Intl.DateTimeFormat handles the padding for you if you are formatting for display.
Is getMinutes() always the same as getUTCMinutes()?
No. Timezones such as India (UTC+5:30) and Nepal (UTC+5:45) use non-whole-hour offsets, so the local and UTC minutes differ. Check date.getTimezoneOffset() % 60 to see whether the current zone is offset by whole hours.
How do I round a time to the nearest 15 minutes?
Compute Math.round(date.getMinutes() / 15) * 15 and pass it to setMinutes(value, 0, 0) — the extra zeros clear the seconds and milliseconds. Use Math.floor instead when you want to snap down rather than to the nearest slot.
More examples
Snapping to a 15-minute slot
Flooring the minutes maps each sample onto 0, 15, 30 or 45. Passing 0, 0 to setMinutes() clears the seconds and milliseconds too, which a slot boundary needs.
function snapTo(date, step) {
const d = new Date(date);
d.setMinutes(Math.floor(d.getMinutes() / step) * step, 0, 0);
return d;
}
const samples = [0, 7, 15, 29, 44, 59]
.map((m) => new Date(2024, 0, 1, 10, m, 33, 400));
console.log(samples.map((d) => d.getMinutes()));
console.log(samples.map((d) => snapTo(d, 15).getMinutes()));
console.log(snapTo(samples[1], 15).getSeconds());Minutes since the start of the hour
getMinutes() truncates to whole minutes at 42, while the timestamp difference keeps the half-minute as 42.5. Which one you want depends on whether partial minutes count.
const start = new Date(2024, 0, 1, 14, 0, 0);
const now = new Date(2024, 0, 1, 14, 42, 30);
console.log(now.getMinutes());
console.log((now - start) / 60000); // includes the seconds
console.log(Math.floor((now - start) / 60000));
console.log(60 - now.getMinutes()); // minutes until the next hourLocal versus UTC minutes
The two match only in whole-hour timezones, which the offset check confirms. In a half-hour zone such as IST the local minutes sit 30 apart from the UTC ones.
const d = new Date();
console.log(d.getMinutes() === d.getUTCMinutes());
console.log(d.getTimezoneOffset() % 60 === 0);
// India is UTC+5:30, so the minutes differ there
const india = new Date(Date.UTC(2024, 0, 1, 12, 0));
console.log(india.getUTCMinutes());
console.log((india.getUTCMinutes() + 30) % 60); // what IST would show
Discussion