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/sethours/index.html | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html') diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html new file mode 100644 index 0000000000..f23dab9d13 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/date/sethours/index.html @@ -0,0 +1,88 @@ +--- +title: Date.prototype.setHours() +slug: Web/JavaScript/Reference/Global_Objects/Date/setHours +translation_of: Web/JavaScript/Reference/Global_Objects/Date/setHours +--- +
{{JSRef("Global_Objects", "Date")}}
+ +

setHours() 方法根据本地时间为一个日期对象设置小时数,返回从1970-01-01 00:00:00 UTC 到更新后的 {{jsxref("Global_Objects/Date", "日期")}} 对象实例所表示时间的毫秒数。

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

语法

+ +
dateObj.setHours(hoursValue[, minutesValue[, secondsValue[, msValue]]])
+
+ +

JavaScript 1.3版本之前

+ +
dateObj.setHours(hoursValue) 
+ +

参数

+ +
+
hoursValue
+
一个 0 到 23 的整数,表示小时。
+
minutesValue
+
一个 0 到 59 的整数,表示分钟。
+
secondsValue
+
一个 0 到 59 的整数,表示秒数。如果指定了 secondsValue 参数,则必须同时指定 minutesValue 参数。
+
msValue
+
一个 0 到 999 的数字,表示微秒数,如果指定了 msValue 参数,则必须同时指定 minutesValue 和 secondsValue 参数。
+
+ +

描述

+ +

如果不指定 minutesValuesecondsValue 和 msValue 参数,则会使用{{jsxref("Date.getMinutes", "getMinutes()")}},{{jsxref("Date.getSeconds", "getSeconds()")}} 和{{jsxref("Date.getMilliseconds", "getMilliseconds()")}} 方法的返回值。

+ +

如果有一个参数超出了合理范围,setHours 会相应地更新日期对象中的日期信息。例如,如果为 secondsValue 指定了 100,则分钟会加 1,然后秒数使用 40。

+ +

例子

+ +

例子:使用setHours方法

+ +
var theBigDay = new Date();
+theBigDay.setHours(7);
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + +
规范版本规范状态注解
ECMAScript 1st Edition. Implemented in JavaScript 1.0StandardInitial definition.
{{SpecName('ES5.1', '#sec-15.9.5.34', 'Date.prototype.setHours')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-date.prototype.sethours', 'Date.prototype.setHours')}}{{Spec2('ES6')}} 
+ +

浏览器兼容性

+ + + +

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

+ +

相关链接

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