--- title: Date.prototype.getHours() slug: Web/JavaScript/Reference/Global_Objects/Date/getHours translation_of: Web/JavaScript/Reference/Global_Objects/Date/getHours ---
{{JSRef}}

 

Il metodo  getHours() restituisce l'ora per la data specificata in accordo con l'ora locale.

{{EmbedInteractiveExample("pages/js/date-gethours.html")}}

Sintassi

dateObj.getHours()

Valore di ritorno

Un numero di tipo integer, tra 0 e 23, rappresentante l'ora per la data fornita in accordo con l'ora locale.

Esempi

Utilizzando getHours()

La seconda dichiarazione qui sotto assegna il valore 23 alla variabile hours, basata sul valore dell'oggetto {{jsxref("Global_Objects/Date", "Date")}} Xmas95.

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

console.log(hours); // 23

Specificazioni

Specification Status Comment
{{SpecName('ES1')}} {{Spec2('ES1')}} Definizione iniziale. Implementata in JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.9.5.18', 'Date.prototype.getHours')}} {{Spec2('ES5.1')}}  
{{SpecName('ES6', '#sec-date.prototype.gethours', 'Date.prototype.getHours')}} {{Spec2('ES6')}}  
{{SpecName('ESDraft', '#sec-date.prototype.gethours', 'Date.prototype.getHours')}} {{Spec2('ESDraft')}}  

Browser compatibility

{{Compat("javascript.builtins.Date.getHours")}}

See also