setSeconds 方法 (Date)

使用当地日期时间设置Date对象中的秒钟值。

语法

dateObj.setSeconds(numSeconds[, numMilli])

参数

dateObj

必要参数。任何Date对象。

numSeconds

必要参数。任何等于秒值的数字。

numMilli

可选参数。一个等于毫秒值的数字。

备注

所有的取用可选的参数的set方法,如果你没有指定可选的参数的话,就使用对应的get方法返回的值。例如,如果设有指定mumMilli参数没有指定,JavaScript就会使用从getMilliseconds方法返回的值。

若要使用协调通用时间(UTC)设置秒钟值,请使用setUTCSeconds方法。

如果参数值大于其取值范围或者为负,则会相应地修改存储的其他值。例如,如果存储的日期是“Jan 5, 1996 00:00:00”,而且调用了函数setSeconds(150),日期将变为“Jan 5, 1996 00:02:30”。

setHours方法可用于设置小时、分钟、秒和毫秒。

示例

下面的示例演示了setSeconds方法的用法。

function SetSecondsDemo(nsec){
  var d = new Date();     //Create Date object.
  d.setSeconds(nsec);     //Set seconds.
  var s = "Current setting is ";
  s += d.toLocaleString();
  return(s);         //Return new setting.
}

必备条件

在以下文档模式中受支持:怪异模式、Internet Explorer 6标准模式、Internet Explorer 7标准模式、Internet Explorer 8标准模式、Internet Explorer 9标准模式、Internet Explorer 10标准模式、Internet Explorer 11标准模式。应用商店应用(Windows 8和Windows Phone 8.1)中也受支持。请参阅版本信息

Applies ToDate Object

如果你喜欢这篇文章,敬请给站长打赏↑

除特别注明外,本站所有文章均为本站站长原译,转载请注明出处。