setUTCSeconds 方法 (Date)
使用协调通用时间(UTC)设置Date对象中的秒钟值。
语法
dateObj.setUTCSeconds(numSeconds[, numMilli])
参数
dateObj
必要参数。任何Date对象。
numSeconds
必要参数。任何等于秒值的数字。
numMilli
可选参数。一个等于毫秒值的数字。
备注
所有的取用可选的参数的set方法,如果你没有指定可选的参数的话,就使用对应的get方法返回的值。例如,如果未指定numMilli参数,则JavaScript将使用从getUTCMilliseconds方法返回的值。
若要使用当地时间设置秒值,请使用setSeconds方法。
如果参数值大于其取值范围或者为负,则会相应地修改存储的其他值。例如,如果存储的日期是“Jan 5, 1996 00:00:00.00”,而且调用了函数setSeconds(150),日期将变为“Jan 5, 1996 00:02:30.00”。
setUTCHours方法可用于设置小时、分钟、秒和毫秒。
示例
下面的示例演示了setUTCSeconds方法的用法。
function SetUTCSecondsDemo(nsec){ // Create Date object. var d = new Date(); // Set UTC seconds. d.setUTCSeconds(nsec); var s = "Current setting is "; s += d.toUTCString(); // Return new setting. return(s); }
必备条件
在以下文档模式中受支持:怪异模式、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 To: Date Object