js 月份 日期,js日期

來源:互聯網
上載者:User

js 月份 日期,js日期

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title><style type="text/css">table tr td{ border-top:#FF0000 solid 1px;  background-color:#00CC33; text-align:center; line-height:24px;}</style><script type="text/javascript" src="jquery.1.8.3.js"></script><script type="text/javascript">$(document).ready(function(){printDate();});function printDate(){var html='<table style="text-align:center;border:1px;">';html+='<tr><td>星期一</td><td>星期二</td><td>星期三</td><td>星期四</td><td>星期五</td><td>星期六</td><td>星期日</td></tr>';var index=0;var arr=[7,1,2,3,4,5,6];//總天數var count = getCountDays();// 得到每個月的第一天星期幾var curDate = settime();html+="<br/><br/>"+(curDate.getMonth()+1)+"  月份日期<Br/><Br/>";curDate.setDate(1);// 判斷這個月的第一天星期幾var week = curDate.getDay();// 列印的空格數var first = arr[week];for(var i=1;i<=count;i++){if(i == 1){html+='<tr>';}if(index==7){html+="</tr><tr>";index=0;}if(i==1 &&first<=7){// 判斷每個月的第一個是星期幾,並列印相應的空格for(var j =1;j<=7;j++){if(j==first){html+='<td>'+i+'</td>';break;}else{html+='<td></td>';}index++;}}else{html+='<td>'+i+'</td>';}index++;}$("body").append(html);}function getCountDays() {        var curDate = settime();        /* 擷取當前月份 */        var curMonth = curDate.getMonth();       /*  產生實際的月份: 由於curMonth會比實際月份小1, 故需加1 */       curDate.setMonth(curMonth + 1);       /* 將日期設定為0, 這裡為什麼要這樣設定, 我不知道原因, 這是從網上學來的 */       curDate.setDate(0);       /* 返回當月的天數 */       return curDate.getDate();}// 自訂日期,然後根據月份輸出該月所有天數,與系統日期對應function settime(){var str ='2015-05-12 23:13:15';str = str.replace(/-/g,"/");var date = new Date(str );return date;}</script></head><body></body></html>



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.