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.
Resumo
O método getHours()
retorna a hora para a data especificada, de acordo com a hora local.
Sintaxe
dateObj.getHours()
Parâmetros
Nenhum.
Retorna
O valor retornado por getHours()
é um inteiro entre 0 e 23.
Exemplos
Exemplo: Usando getHours()
O segundo statement abaixo atribui o valor 23 à variável hours
, baseado no valor do objeto Date
Xmas95
.
js
var Xmas95 = new Date("December 25, 1995 23:15:30");
var hours = Xmas95.getHours();
console.log(hours); // 23
Especificações
Specification |
---|
ECMAScript® 2025 Language Specification # sec-date.prototype.gethours |
Compatibilidade com navegadores
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.