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)      
廣告

© . All rights reserved.