一天一個js(8)擷取某年某月某日是周幾、以及該月1號周幾、以及該月多少天

來源:互聯網
上載者:User

擷取某年某月某日是周幾,以及該月1號周幾,以及該月多少天。
[javascript]
var    Nowdate = ("2012-11-22").split("-"),    //擷取某一日期  
        NowYear = parseInt(Nowdate[0]),    //某年份  
        NowMonth = parseInt(Nowdate[1]),    //某月份  
        Nowday = parseInt(Nowdate[2]),    //某天  
        date = new Date(), 
        weekday=new Array(7); 
weekday[0]="星期日"; 
weekday[1]="星期一"; 
weekday[2]="星期二"; 
weekday[3]="星期三"; 
weekday[4]="星期四"; 
weekday[5]="星期五"; 
weekday[6]="星期六"; 
date.setFullYear(NowYear);//把當前年份設為某年  
date.setMonth(NowMonth-1);//把當前月份設為某月  
date.setDate(Nowday);//把當前日設為某天  
document.write(NowYear+"年"+NowMonth+"月"+Nowday+"號是"+weekday[date.getDay()]+"<br />"); 
 
date.setDate(1);    //把當前日期設為該月1號  
document.write(NowYear+"年"+NowMonth+"月1號是"+weekday[date.getDay()]+"<br />"); 
 
date.setMonth(date.getMonth()+1);                                //月份+1(即下月1號)          
var LastDay = new Date(date-3600000*24);                //日份-1(即本月最後一天)  
document.write(NowYear+"年"+NowMonth+"月一共"+LastDay.getDate()+"天<br />"); 

var    Nowdate = ("2012-11-22").split("-"),    //擷取某一日期
        NowYear = parseInt(Nowdate[0]),    //某年份
        NowMonth = parseInt(Nowdate[1]),    //某月份
        Nowday = parseInt(Nowdate[2]),    //某天
        date = new Date(),
        weekday=new Array(7);
weekday[0]="星期日";
weekday[1]="星期一";
weekday[2]="星期二";
weekday[3]="星期三";
weekday[4]="星期四";
weekday[5]="星期五";
weekday[6]="星期六";
date.setFullYear(NowYear);//把當前年份設為某年
date.setMonth(NowMonth-1);//把當前月份設為某月
date.setDate(Nowday);//把當前日設為某天
document.write(NowYear+"年"+NowMonth+"月"+Nowday+"號是"+weekday[date.getDay()]+"<br />");

date.setDate(1);    //把當前日期設為該月1號
document.write(NowYear+"年"+NowMonth+"月1號是"+weekday[date.getDay()]+"<br />");

date.setMonth(date.getMonth()+1);                                //月份+1(即下月1號)       
var LastDay = new Date(date-3600000*24);                //日份-1(即本月最後一天)
document.write(NowYear+"年"+NowMonth+"月一共"+LastDay.getDate()+"天<br />");

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.