JavaScript getMinutes()

getMinutes() returns the minutes component of a JavaScript Date according to local time. The normal range is 0 to 59.

const now = new Date();
const value = now.getMinutes();
console.log(value);

getMinutes() Syntax and Return Value Top ↑

const value = date.getMinutes();

The method takes no parameters. If the Date is invalid, it returns NaN.

Pad Minutes to Two Digits Top ↑

const value = String(date.getMinutes()).padStart(2, "0");

Using getMinutes() in a Clock Top ↑

const now = new Date();
const hh = String(now.getHours()).padStart(2, "0");
const mm = String(now.getMinutes()).padStart(2, "0");
const ss = String(now.getSeconds()).padStart(2, "0");
console.log(`${{hh}}:${{mm}}:${{ss}}`);

For an updating display, see the JavaScript clock and timer tutorial.

getMinutes() and Its UTC Equivalent Top ↑

const localValue = date.getMinutes();
const utcValue = date.getUTCMinutes();

Use the local method for the host's local time and the UTC method when your logic is explicitly based on UTC. See UTC date methods.

Invalid Dates Top ↑

const bad = new Date("invalid");
console.log(bad.getMinutes()); // NaN

Previous: getHours()

Reading vs Setting Minutes Top ↑

getMinutes() reads the value; setMinutes() changes it. For delayed execution, use a timer rather than repeatedly changing a Date object.

Common getMinutes() Mistakes Top ↑

  • Assuming the returned number is already zero-padded for display.
  • Mixing local and UTC components in the same calculation.
  • Ignoring invalid Date values.
  • Using raw numeric components when locale-aware formatting would better serve users.

Date Reference Next Date Method




Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer