JavaScript Date getMinutes() 方法
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 作为分钟值。

