Share via


setUTCSeconds 方法

更新:2007 年 11 月

使用 Coordinated Universal Time (UTC) 設定 Date 物件中的秒數值。

 function setUTCSeconds(numSeconds : Number [, numMilli : Number ])

引數

  • numSeconds
    必要項。等於秒數值的數值。

  • numMilli
    選擇項。等於毫秒值的數值。

備註

如果不指定選擇性引數,則所有需要選擇性引數的 set 方法都會使用對應的 get 方法所傳回的數值。例如,如果 numMilli 引數是沒有指定的選擇性引數,JScript 就會使用 getUTCMilliseconds 方法所傳回的值。

若要利用本地時間設定秒鐘值,請使用 setSeconds 方法。

如果引數值大於其範圍或者是負數的話,其他的儲存值都會跟著修改。例如,儲存的日期如果是 "Jan 5, 1996 00:00:00.00",這時若呼叫 setSeconds(150),則日期會變成 "Jan 5, 1996 00:02:30.00"。

範例

下列範例說明如何使用 setSeconds 方法。

function SetUTCSecondsDemo(nsec, nmsec){
   var d, s;                       //Declare variables.
   d = new Date();                 //Create Date object.
   d.setUTCSeconds(nsec, nmsec);   //Set UTC seconds and milliseconds.
   s = "Current UTC milliseconds setting is ";
   s += d.getUTCMilliseconds();    //Get new setting.
   return(s);                      //Return new setting.
}

需求

3 版

套用至:

Date 物件

請參閱

參考

getSeconds 方法

getUTCSeconds 方法

setSeconds 方法