文字
分享


setSeconds 方法

设置 Date 对象中用 本地时间表示的秒钟值。

dateObj.setSeconds(numSeconds[, numMilli])

参数

dateObj

必选项。任意 Date 对象。

numSeconds

必选项。等于秒钟值的数值。

numMilli

可选项。等于毫秒值的数值。

说明

如果没有指定可选项,那么所有使用可选项的 set 方法都将使用从相应的 get 方法返回的数值作为可选项的数值。例如,如果 numMilli 参数是可选的,但是没有被指定,JScript 将使用从 getMilliseconds 方法返回的值作为该参数的值。

要设置用全球标准时间 (UTC)表示的秒钟值,请使用 setUTCSeconds 方法。

如果一个参数的值超出了其取值范围或者是一个负数,其他保存的值将相应地得到修改。例如如果所保存的日期是 "Jan 5, 1996 00:00:00" 而且调用了函数 setSeconds(150),日期将被改变为 "Jan 5, 1996 00:02:30."

示例

下面这个例子说明了 setSeconds 方法的用法:

1

2

3

4

5

6

7

8

9

<code>function SetSecondsDemo(nsec, nmsec){

   var d, s;                   // </code>声明变量。

   <code>var sep = ":";</code>

<code>   d = new Date();             // </code>创建<code> Date </code>对象。

   <code><span class="cfe"><b>d.setSeconds(</b></span>nsec<span class="cfe"><b>, </b></span>nmsec<span class="cfe"><b>)</b></span>;  // </code>设置秒和毫秒。

   <code>s = "Current setting is ";</code>

<code>   s += d.toLocaleString() + sep + d.getMilliseconds();</code>

   <code>return(s);                  // </code>返回新的设置。

}

要求

版本 1

请参阅

Date 对象的方法 | getSeconds 方法 | getUTCSeconds 方法 | setUTCSeconds 方法

应用于: Date 对象

上一篇:setMonth 方法下一篇:setTime 方法