目录

JavaScript Date setMinutes()

示例1

将分钟设置为 17:

const d = new Date();
d.setMinutes(17);
亲自试一试 »

描述

setMinutes()设置日期的分钟。

该方法也可用于设置秒和毫秒。

示例2

将日期时间设置为 90 分钟:

const d = new Date();
d.setMinutes(d.getMinutes() - 90);
亲自试一试 »

浏览器支持

setMinutes()是 ECMAScript1 (ES1) 功能。

所有浏览器均完全支持 ES1 (JavaScript 1997):

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes

语法

Date.setMinutes( min, sec, millisec)

参数值

Parameter Description
min Required. An integer representing the minutes.

Expected values are 0-59, but other values are allowed:

  • -1 will result in the last minute of the previous hour
  • 60 will result in the first minute of the next hour
sec Optional. An integer representing the seconds

Expected values are 0-59, but other values are allowed:

  • -1 will result in the last second of the previous minute
  • 60 will result in the first second of the next minute
millisec Optional. An integer representing the milliseconds

Expected values are 0-999, but other values are allowed:

  • -1 will result in the last millisecond of the previous second
  • 1000 will result in the first millisecond of the next second


技术细节

返回值: 一个数字,表示日期对象与 1970 年 1 月 1 日午夜之间的毫秒数
JavaScript 版本: ECMA脚本1