JavaScript 中的 Date.getMinutes() 方法用于检索日期对象的分钟组件,将小时的分钟表示为介于 0 和 59 之间的数字。它根据系统的本地时区提取日期对象的分钟部分。
如果未将日期作为参数提供,则 getMinutes() 方法将根据本地时间返回调用它的 Date 对象的分钟部分。如果 Date 对象无效,该方法返回 NaN 作为结果。
语法
以下是 JavaScript Date.getMinutes() 方法的语法 -
getMinutes();
此方法不接受任何参数。
返回值
此方法返回一个整数值,该值表示给定 Date 对象的分钟部分,范围从 0 到 59。
示例 1
在以下示例中,我们将演示 JavaScript Date.getMinutes() 方法的基本用法 -
<html>
<body>
<script>
const currentDate = new Date();
const minutes = currentDate.getMinutes();
document.write("Current Minutes:", minutes);
</script>
</body>
</html>
输出
上述程序根据当地时间返回日期的分钟数。
示例 2
在这里,我们使用 getMinutes() 方法从提供的日期获取分钟组件。
<html>
<body>
<script>
const specificDate = new Date('2023-12-25 12:45:30');
const minutes = specificDate.getMinutes();
document.write("Minutes of provided Date:", minutes);
</script>
</body>
</html>
输出
上面的程序返回整数 45 作为分钟值。