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

setMonth() 方法根据本地时间为一个设置年份的日期对象设置月份。

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

语法

+ +
dateObj.setMonth(monthValue[, dayValue])
+ +

JavaScript 1.3版本之前

+ +
dateObj.setMonth(monthValue)
+ +

参数

+ +
+
monthValue
+
介于 0 到 11 之间的整数(表示一月到十二月)。
+
+ +
+
dayValue
+
从 1 到 31 之间的整数,表示月份中的第几天。0为上个月最后一天
+
返回值!
+
基于 1 January 1970 00:00:00 UTC 开始计算的毫秒数
+
+ +

描述

+ +

如果不指定 dayValue 参数,就会使用 {{jsxref("Date.getDate", "getDate")}} 方法的返回值。

+ +

如果有一个指定的参数超出了合理范围,setMonth 会相应地更新日期对象中的日期信息。例如,为 monthValue 指定 15,则年份会加 1,月份将会使用 3。

+ +

例子

+ +

例子:使用setMonth方法

+ +
var theBigDay = new Date();
+theBigDay.setMonth(6);
+
+ +

规范

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

浏览器兼容性

+ + + +

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

+ +

相关链接

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