梦之都
JavaScript教程
getMonth
函数返回date对象中的中文的月份
使用
switch
的方式
使用JavaScript数组的方式
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>JavaScript getMonth() 函数打印中文的月份示例</title> </head> <body> <script type="text/javascript"> document.write("本月是"); 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("发生错误"); } } </script> <p>使用JavaScript数组的方式</p> <script type="text/javascript"> var monthes = new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"); month = d.getMonth(); document.write("本月是"+monthes[month]); </script> </body> </html>