ES6 - setUTCHours() 方法



JavaScript 的 date setUTCHours() 方法根據本地時間設定指定日期的小時。

語法

Date.setUTCHours(hoursValue[, minutesValue[, secondsValue[, msValue]]])      

引數

  • hoursValue − 一個介於 0 和 23 之間的整數,表示小時。

  • minutesValue − 一個介於 0 和 59 之間的整數,表示分鐘。

  • secondsValue − 一個介於 0 和 59 之間的整數,表示秒數。如果指定 secondsValue 引數,則也必須指定 minutesValue。

  • msValue − 一個介於 0 和 999 之間的數字,表示毫秒。如果指定 msValue 引數,則也必須指定 minutesValue 和 secondsValue。

如果不指定 minutesValue、secondsValue 和 msValue 引數,則使用 getUTCMinutes、getUTCSeconds 和 getUTCMilliseconds 方法返回的值。

如果指定的引數超出預期範圍,則 setUTCHours 會嘗試相應地更新 Date 物件中的日期資訊。例如,如果對 secondsValue 使用 100,則分鐘將增加 1(min + 1),並且將使用 40 表示秒數。

示例

var dt = new Date( "Aug 28, 2008 23:30:00" ); 
dt.setUTCHours( 12); 
console.log( dt );       

輸出

Thu Aug 28 2008 17:30:00 GMT+0530 (India Standard Time)        
廣告

© . All rights reserved.