嘿嘿,写了一个显示日期的js~
3 回答
<!-- <!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 getDay() 函数打印中文的星期几示例</title> </head> <body> <p>使用<a href="http://www.dreamdu.com/javascript/switch_case/">switch</a>语句的方式</p> <script type="text/javascript"> document.write("今天是"); var d = new Date(); switch(d.getDay()) { 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("星期六"); } break; default: { document.write("发生错误"); } } </script> <p>使用JavaScript数组的方式</p> <script type="text/javascript"> var days = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六"); day = d.getDay(); document.write("今天是"+days[day]); </script> </body> </html> --> <html> <head> <title>kong</title> <script> var riqi=new Date(); var ri=riqi.getDate(); var nian=riqi.getFullYear()+1; var yue=riqi.getMonth(); var xingqi=riqi.getDay(); switch(xingqi) { case 0:xq="日";break; case 1:xq="一";break; case 2:xq="二";break; case 3:xq="三";break; case 4:xq="四";break; case 5:xq="五";break; case 6:xq="六";break; } document.write("今天是"+nian+"年"+yue+"月"+ri+"日"+"星期"+xq); </script> </head> <body> </body> </html>
不仅年份要加1,getDay()当为星期日的时候,返回值是0
举报
0/150
提交
取消