ES6 - setSeconds() 方法

JavaScript date setSeconds() 方法根据本地时间设置指定日期的秒数。

语法

Date.setSeconds(secondsValue[, msValue])

参数

  • secondsValue − 0 到 59 之间的整数。

  • msValue − 0 到 999 之间的数字,表示毫秒。

如果您未指定 msValue 参数,则使用 getMilliseconds 方法返回的值。如果您指定的参数超出预期范围,setSeconds 将尝试相应地更新 Date 对象中的日期信息。例如,如果将 secondsValue 设置为 100,则 Date 对象中存储的分钟数将增加 1,而秒数将设置为 40。

示例

var dt = new Date( "Aug 28, 2008 23:30:00" ); 
dt.setSeconds( 80 ); 
console.log( dt );       

输出

Thu Aug 28 2008 23:31:20 GMT+0530 (India Standard Time)