Categories: Javascript对象tips

JavaScript对象:JavaScript setUTCMonth() 方法

返回到:JavaScript对象:JavaScript Date 对象

定义和用法

setUTCMonth() 方法用于根据世界时 (UTC) 来设置月份。

注意: 0(一月) ~ 11(十二月)

这个方法可以适用于设置月份的某一天。

提示:协调世界时,又称世界统一时间,世界标准时间,国际协调时间,简称UTC( Universal Coordinated Time ) 。

所有主要浏览器都支持 setUTCMonth() 方法

语法

Date.setUTCMonth(month,day)

参数值

参数描述
month必需。要给 dateObject 设置的月份字段的值,用世界时表示。
该参数是 0(一月) ~ 11(十二月) 之间的整数:
-1 为上一年的最后一月。
12 为下一年的第一个月。
13 为下一年的第二月。
day可选。月份中的某一天。
在 1 ~ 31 之间的整数,用作 date Object 的天字段,用世界时表示。
0 为上一个月的最后一小时。
-1 为上一个月最后一小时之前的小时时间。

如果当月有31天:32 为下一个月的第一天。
如果当月有30天:32 为下一个月的第二天。

返回值

Type描述
Number调整过的日期的毫秒表示。

技术细节

JavaScript 版本:1.3

实例

DEMO1:将月份设置为 4 (4月份)。

<!DOCTYPE html>
<html>
 <title>Web176教程(Web176.com)</title>
<body>

<p id="demo">Click the button to display the date after changing the month.</p>

<button >

DEMO2:设置月份为 4 (4月份) 日期为20号。

<!DOCTYPE html>
<html>
 <title>Web176教程(Web176.com)</title>
<body>

<p id="demo">Click the button to display the date after changing the month and day.</p>

<button >

DEMO3:设置日期为上一个月的最后一天。

<!DOCTYPE html>
<html>
 <title>Web176教程(Web176.com)</title>
<body>

<p id="demo">Click the button to display the date after setting the date to be the last day of last month.</p>

<button >
terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts

聊聊vue3中的defineProps

在Vue 3中,defineP…

7 天 ago

在 Chrome 中删除、允许和管理 Cookie

您可以选择删除现有 Cooki…

2 周 ago

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

3 周 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

4 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

4 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

1 月 ago