Die getHours()
Methode gibt die Stunde eines Datums bezüglich der Ortszeit zurück.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Syntax
dateObj.getHours()
Rückgabewert
Eine ganze Zahl zwischen 0 und 23, welche die Stunde der gegebenen Zeit bezüglich der lokalen Zeit angibt.
Beispiele
Einsatz von getHours()
Im zweiten Statement wird die Variable hours
mit dem Wert 23 initialisiert. Dieses geschied mit dem Wert des Date
Objektes Xmas95
.
var Xmas95 = new Date('December 25, 1995 23:15:30'); var hours = Xmas95.getHours(); console.log(hours); // 23
Spezifikationen
Spezifikation | Status | Kommentar |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | Initiale Definition. Implementiert in JavaScript 1.0. |
ECMAScript 5.1 (ECMA-262) Die Definition von 'Date.prototype.getHours' in dieser Spezifikation. |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) Die Definition von 'Date.prototype.getHours' in dieser Spezifikation. |
Standard | |
ECMAScript Latest Draft (ECMA-262) Die Definition von 'Date.prototype.getHours' in dieser Spezifikation. |
Entwurf |
Browserkompatibilität
The compatibility table in 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.
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Grundlegende Unterstützung | Chrome Vollständige Unterstützung Ja | Edge Vollständige Unterstützung Ja | Firefox Vollständige Unterstützung 1 | IE Vollständige Unterstützung Ja | Opera Vollständige Unterstützung Ja | Safari Vollständige Unterstützung Ja | WebView Android Vollständige Unterstützung Ja | Chrome Android Vollständige Unterstützung Ja | Edge Mobile Vollständige Unterstützung Ja | Firefox Android Vollständige Unterstützung 4 | Opera Android Vollständige Unterstützung Ja | Safari iOS Vollständige Unterstützung Ja | Samsung Internet Android Vollständige Unterstützung Ja | nodejs Vollständige Unterstützung Ja |
Legende
- Vollständige Unterstützung
- Vollständige Unterstützung