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

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

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

内容目录

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

例如:2008年8月15日,就返回7;2013年1月30日,就返回0。

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

语法

date.getMonth( )

返回值

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

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

示例&说明

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

// 定义一个"2002-06-30 12:11:59 230"的Date对象
var date2 = new Date(2002, 5, 30, 12, 11, 59, 230);
document.writeln( date2.getMonth() ); // 5

// 定义一个"2009-01-18"的Date对象
var date3 = new Date(2009, 0, 18);
document.writeln( date3.getMonth() ); // 0

运行代码

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

0 条评论

撰写评论

打开导航菜单