JavaScript getMonth() 函数
date.getMonth() -- 返回date对象中的月份数(0-11)
- month,中文"月"的意思
- 引用网址:http://www.dreamdu.com/javascript/date.getMonth/
getMonth函数语法
date.getMonth();
getMonth函数返回值
- 返回date对象的月份数
- 此值为0(一月)-11(12月)之间的整数
getMonth函数示例
vard=newDate();document.write(d.getMonth());
返回数字形式的月份
vard=newDate();switch(d.getMonth()){case0:{document.write("一月");}break;case1:{document.write("二月");}break;case2:{document.write("三月");}break;case3:{document.write("四月");}break;case4:{document.write("五月");}break;case5:{document.write("六月");}break;case6:{document.write("七月");}case7:{document.write("八月");}break;case8:{document.write("九月");}break;case9:{document.write("十月");}break;case10:{document.write("十一月");}break;case11:{document.write("十二月");}break;default:{document.write("发生错误");}}
使用switch返回中文的月份
varmonthes=newArray("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");month=d.getMonth();document.write("本月是"+monthes[month]);
使用JavaScript数组返回中文的月份
JavaScript getMonth() 函数示例 -- 可以尝试编辑
延伸阅读
- JavaScript getUTCMonth 函数
- JavaScript setMonth 函数