getMonth 方法
更新:2007 年 11 月
使用当地时间返回 Date 对象中的月份值。
function getMonth() : Number
备注
若要使用协调通用时间 (UTC) 获取月份值,请使用 getUTCMonth 方法。
getMonth 方法返回一个介于 0 到 11 之间的整数,该整数指示 Date 对象中的月份值。所返回的整数不是用于指示月份的传统数字。而是要比传统数字小 1。如果一个 Date 对象中存储的值为“Jan 5, 1996 08:47:00”,那么 getMonth 将返回 0。
示例
下面的示例阐释了 getMonth 方法的用法:
function DateDemo(){
var d, s = "Today's date is: ";
d = new Date();
s += (d.getMonth() + 1) + "/";
s += d.getDate() + "/";
s += d.getYear();
return(s);
}