This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Date.prototype.getHours()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015년 7월⁩.

getHours() 메서드는 주어진 날짜의 현지 시간 기준 시를 반환합니다.

시도해 보기

const birthday = new Date("March 13, 08 04:20");

console.log(birthday.getHours());
// Expected output: 4

구문

js
dateObj.getHours();

반환 값

주어진 날짜의 현지 시간 기준 시를 나타내는 0에서 23 사이의 정수.

예제

getHours() 사용하기

아래의 두 번째 명령문은 Date 객체 Xmas95 날짜의 시를 hours 변수에 할당합니다.

js
var Xmas95 = new Date("December 25, 1995 23:15:30");
var hours = Xmas95.getHours();

console.log(hours); // 23

명세

Specification
ECMAScript® 2026 Language Specification
# sec-date.prototype.gethours

브라우저 호환성

같이 보기