Date.prototype.getHours()
getHours()
方法基於本地時區回傳指定日期的小時數。
嘗試一下
語法
getHours()
返回值
一個基於本地時區表示指定日期的小時、介於 0 至 23 的整數值。
範例
使用 getHours()
下方第二行陳述式將 Date
物件 xmas95
的值 23,指派給變數 hours
。
const xmas95 = new Date("December 25, 1995 23:15:30");
const hours = xmas95.getHours();
console.log(hours); // 23
規範
Specification |
---|
ECMAScript Language Specification # sec-date.prototype.gethours |
瀏覽器相容性
BCD tables only load in the browser