getMinutes()
ES1+Returns the minutes (0-59) in the specified date according to local time.
Syntax
date.getMinutes()Return Value
number
A number (0-59) representing the minutes
Examples
JavaScript
const date = new Date('2024-01-15T14:30:45');
console.log(date.getMinutes()); Output:
// 30
📌 When to Use
Use getMinutes() for time displays, scheduling precision, or calculating time intervals within an hour.
⚠️ Common Mistakes
Forgetting to pad single-digit minutes with a leading zero for display.
✅ Best Practices
Pad minutes for display: String(date.getMinutes()).padStart(2, "0").
⚡ Performance Notes
getMinutes() is O(1) constant time. No performance concerns.
🌍 Real World Example
Meeting Time Formatter
Format meeting time with proper padding for a clean display.
function formatMeetingTime(date) {
const d = new Date(date);
const hours = d.getHours();
const minutes = d.getMinutes();
const ampm = hours >= 12 ? 'PM' : 'AM';
const hour12 = hours % 12 || 12;
return `${hour12}:${String(minutes).padStart(2, '0')} ${ampm}`;
}
console.log(formatMeetingTime('2024-03-15T09:05:00')); // "9:05 AM"
console.log(formatMeetingTime('2024-03-15T14:30:00')); // "2:30 PM"