ES6 - setHours() 方法



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

語法

Date.setHours(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 和 getMilliseconds 方法返回的值。

示例

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

輸出

Thu Aug 28 2008 02:30:00 GMT+0000 (UTC)     
廣告

© . All rights reserved.