内容目录 语法返回值示例&说明 getUTCMonth()函数用于使用UTC时间返回当前Date对象中的月份值。也就是"年月日"中"月"的数值。 例如:2008年8月15日,就返回7;2013年1月30日,就返回0(以上日期均基于UTC时间)。 该函数属于Date对象,所有主流浏览器均支持该函数。 语法 复制全屏全选JavaScript:date.getUTCMonth( ) 返回值 getUTCMonth()函数的返回值为Number类型,返回当前Date对象基于UTC时间的月份值。该值介于 [0, 11] 之间。 其中,0 ~ 11 分别表示 1月至12月。 示例&说明 复制全屏全选JavaScript:// 当前运行环境的时区为 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 运行代码
0 条评论
撰写评论