date.getMonth()-- 返回date对象中的月份数(0-11)
getMonth函数语法
date.getMonth();
getMonth函数返回值
- 返回date对象的月份数
- 此值为0(一月)-11(12月)之间的整数
getMonth函数示例
var d = new Date();
document.write(d.getMonth());
返回数字形式的月份
var d = new Date();
switch(d.getMonth())
{
case 0:
{
document.write("一月");
}
break;
case 1:
{
document.write("二月");
}
break;
case 2:
{
document.write("三月");
}
break;
case 3:
{
document.write("四月");
}
break;
case 4:
{
document.write("五月");
}
break;
case 5:
{
document.write("六月");
}
break;
case 6:
{
document.write("七月");
}
case 7:
{
document.write("八月");
}
break;
case 8:
{
document.write("九月");
}
break;
case 9:
{
document.write("十月");
}
break;
case 10:
{
document.write("十一月");
}
break;
case 11:
{
document.write("十二月");
}
break;
default:
{
document.write("发生错误");
}
}
使用switch返回中文的月份
var monthes = new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
month = d.getMonth();
document.write("本月是"+monthes[month]);
使用JavaScript数组返回中文的月份