在 JavaScript 中,Date.getUTCMinutes() 方法用于检索协调世界时 (UTC) 中给定日期和时间的分钟部分。它返回一个介于 0 和 59 之间的整数值,表示指定 UTC 时间的分钟部分。
UTC 代表协调世界时。它是世界调节时钟和时间的主要时间标准。UTC 通常被称为“GMT”(格林威治标准时间)。
语法
以下是 JavaScript Date.getUTCMinutes() 方法的语法 -
getUTCMinutes()
参数
此方法不接受任何参数。
返回值
此方法返回一个整数(介于 0 到 59 之间),表示 UTC 中指定日期和时间的分钟部分。如果日期无效,则返回 NaN。
示例 1
在下面的示例中,我们使用 JavaScript Date.getUTCMinutes() 方法从 date 对象中获取分钟部分,具体取决于 UTC −
<html>
<body>
<script>
const date = new Date();
const minutes = date.getUTCMinutes();
document.write(minutes);
</script>
</body>
</html>
输出
正如我们在下面的输出中看到的那样,它检索了当前的 UTC 分钟。
示例 2
在这里,我们将根据 UTC 创建自定义日期对象。然后,我们使用 getUTCMinutes() 方法提取分钟分量 -
<html>
<body>
<script>
const date = new Date('2024-02-08T10:30:00Z');
const minutes = date.getUTCMinutes();
document.write(minutes);
</script>
</body>
</html>
输出
如果我们执行上述程序,它将返回 “30” 作为分钟值。
示例 3
如果 Date 对象无效,则此方法将返回 “NaN” 作为结果 -
<html>
<body>
<script>
const date = new Date('iunnub');
const minutes = date.getUTCMinutes();
document.write(minutes);
</script>
</body>
</html>
输出
正如我们所看到的,输出返回 “NaN”。