您的浏览器过于古老 & 陈旧。为了更好的访问体验, 请 升级你的浏览器
Ready 发布于2014年08月08日 08:29

原创 JavaScript Date.getUTCMonth() 函数详解

2185 次浏览 读完需要≈ 3 分钟

内容目录

getUTCMonth()函数用于使用UTC时间返回当前Date对象中的月份值。也就是"年月日"中"月"的数值。

例如:2008年8月15日,就返回7;2013年1月30日,就返回0(以上日期均基于UTC时间)。

该函数属于Date对象,所有主流浏览器均支持该函数

语法

date.getUTCMonth( )

返回值

getUTCMonth()函数的返回值为Number类型,返回当前Date对象基于UTC时间的月份值。该值介于 [0, 11] 之间。

其中,0 ~ 11 分别表示 1月至12月

示例&说明

// 当前运行环境的时区为 UTC+8

//定义一个当前时间的Date对象(2014-08-07)
var date = new Date();
document.writeln( date.getUTCMonth() ); // 7

// 定义一个"2002-01-01 03:11:59"的Date对象
var date2 = new Date(2002, 0, 1, 3, 11, 59);
// 此时的UTC时间为"2001-12-31 19:11:59"
document.writeln( date2.getUTCMonth() ); // 11

// 定义一个"2009-05-01"的Date对象
var date3 = new Date(2009, 4, 1);
// 此时的UTC时间为"2009-04-30 16:00:00"
document.writeln( date3.getUTCMonth() ); // 3

运行代码

  • CodePlayer技术交流群1
  • CodePlayer技术交流群2

0 条评论

撰写评论

打开导航菜单