From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/date/gethours/index.html | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/date/gethours') diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html new file mode 100644 index 0000000000..9eb86dc04a --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/date/gethours/index.html @@ -0,0 +1,75 @@ +--- +title: Date.prototype.getHours() +slug: Web/JavaScript/Reference/Global_Objects/Date/getHours +translation_of: Web/JavaScript/Reference/Global_Objects/Date/getHours +--- +

{{JSRef("Global_Objects", "Date")}}

+ +

getHours() 方法根据本地时间,返回一个指定的日期对象的小时。

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

语法

+ +
dateObj.getHours()
+ +

参数

+ +

+ +

返回值

+ +

getHours返回一个0 到 23之间的整数值。

+ +

例子

+ +

例子:使用getHours方法

+ +

下面第二条语句,基于日期对象 Xmas95 的值,把 23 赋值给了变量 hours。

+ +
var Xmas95 = new Date("December 25, 1995 23:15:00");
+var hours = Xmas95.getHours();
+
+alert(hours); // 23
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
规范版本规范状态注解
ECMAScript 1st Edition. Implemented in JavaScript 1.0StandardInitial definition.
{{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')}} 
+ +

浏览器兼容性

+ + + +

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

+ +

相关链接

+ + -- cgit v1.2.3-54-g00ecf