javascript 根据当前周获得当前月

 1 function getMonthByWeek(year, week){
2 var oneminute = 60*1000;
3 var onehour = 60*oneminute;
4 var oneday = 24*onehour;
5 var oneweek = 7*oneday;
6
7 var montharray = new Array(2);
8
9 var datearray = new Array();
10 var begindate = new Date();
11
12 var mybegindate = new Date();
13 var myenddate = new Date();
14
15 begindate.setFullYear(year, 0, 1);
16 begindate.setHours(0);
17 begindate.setMinutes(0);
18 begindate.setSeconds(0);
19 begindate.setMilliseconds(1);
20
21 mybegindate.setFullYear(year, 0, 1);
22 mybegindate.setHours(0);
23 mybegindate.setMinutes(0);
24 mybegindate.setSeconds(0);
25 mybegindate.setMilliseconds(1);
26
27 if(begindate.getDay() == 0){
28 mybegindate.setTime(mybegindate.getTime() + (week-1)*oneweek);
29 }else{
30 mybegindate.setTime(mybegindate.getTime() + (week-1)*oneweek + (7 - begindate.getDay())*oneday);
31 }
32
33 myenddate.setTime(mybegindate.getTime());
34
35 montharray[0] = mybegindate.getMonth();
36
37 for(var i = 1; i < 7; i++){
38 alert(myenddate.toString());
39 myenddate.setTime(mybegindate.getTime() + i*oneday);
40 if(myenddate.getMonth() != montharray[0]){
41 montharray[1] = myenddate.getMonth();
42 }
43 }
44
45 return montharray;
46 }

 

posted @ 2012-03-16 23:51  lostyue  阅读(434)  评论(0编辑  收藏  举报