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 July 2015.
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® 2025 Language Specification # sec-date.prototype.gethours |
브라우저 호환성
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getHours |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.