print?
自己写的:
/*
* 求某年某月的总天数
*/
function getDates(year, month) {
var now2 = new Date(year, month, 0); // 这是本月的最后一天
return now2.getDate();
}
/*
* 获取某年某月1号的星期序号
*/
function getFirstDay(year, month) {
var now = new Date(year, month - 1, 1);
var day = now.getDay();
if (day == 0)
return 7;
else {
return day;
}
}
/*
* 求某年某月星期的总数
*/
function getDays(year, month) {
if (getDates(year, month) - 28 +getFirstDay(year,month) > 8)
return 6;
if (getDates(year, month) == 28
&& getFirstDay(year, month) == 1)
return 4;
else
return 5;
}
其他文章中转来的
1.<mce:script language=javascript><!--
2.//一天含 86,400,000 毫秒(24* 60 * 60*1000)
3.
4.//今天
5.function showToDay()
6.{
7.var Nowdate=new Date();
8.M=Number(Nowdate.getMonth())+1
9.return Nowdate.getYear()+"-"+M+"-"+Nowdate.getDate();
10.}
11.
12.//本周第一天
13.function showWeekFirstDay()
14.{
15.var Nowdate=new Date();
16.var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
17.return WeekFirstDay;
18.}
19.//本周最后一天
20.function showWeekLastDay()
21.{
22.var Nowdate=new Date();
23.var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
24.var WeekLastDay=new Date((WeekFirstDay/1000+6*86400)*1000);
25.return WeekLastDay;
26.}
27.
28.//本月第一天
29.function showMonthFirstDay()
30.{
31.var Nowdate=new Date();
32.var MonthFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth(),1);
33.return MonthFirstDay;
34.}
35.//本月最后一天
36.function showMonthLastDay()
37.{
38.var Nowdate=new Date();
39.var MonthNextFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth
40.
41.()+1,1);
42.var MonthLastDay=new Date(MonthNextFirstDay-86400000);
43.return MonthLastDay;
44.}
45.//上月第一天
46.function showPreviousFirstDay()
47.{
48.var MonthFirstDay=showMonthFirstDay()
49.return new Date(MonthFirstDay.getYear(),MonthFirstDay.getMonth()-
50.
51.1,1)
52.}
53.//上月最后一天
54.function showPreviousLastDay()
55.{
56.var MonthFirstDay=showMonthFirstDay();
57.return new Date(MonthFirstDay-86400000);
58.}
59.//上周第一天
60.function showPreviousFirstWeekDay()
61.{
62.var WeekFirstDay=showWeekFirstDay()
63.return new Date(WeekFirstDay-86400000*7)
64.}
65.//上周最后一天
66.function showPreviousLastWeekDay()
67.{
68.var WeekFirstDay=showWeekFirstDay()
69.return new Date(WeekFirstDay-86400000)
70.}
71.//上一天
72.function showPreviousDay()
73.{
74.var MonthFirstDay=new Date();
75.return new Date(MonthFirstDay-86400000);
76.}
77.//下一天
78.function showNextDay()
79.{
80.var MonthFirstDay=new Date();
81.return new Date((MonthFirstDay/1000+86400)*1000);
82.}
83.//下周第一天
84.function showNextFirstWeekDay()
85.{
86.var MonthFirstDay=showWeekLastDay()
87.return new Date((MonthFirstDay/1000+86400)*1000)
88.}
89.//下周最后一天
90.function showNextLastWeekDay()
91.{
92.var MonthFirstDay=showWeekLastDay()
93.return new Date((MonthFirstDay/1000+7*86400)*1000)
94.}
95.//下月第一天
96.function showNextFirstDay()
97.{
98.var MonthFirstDay=showMonthFirstDay()
99.return new Date(MonthFirstDay.getYear(),MonthFirstDay.getMonth()
100.
101.+1,1)
102.}
103.//下月最后一天
104.function showNextLastDay()
105.{
106.var MonthFirstDay=showMonthFirstDay()
107.return new Date(new Date(MonthFirstDay.getYear
108.
109.(),MonthFirstDay.getMonth()+2,1)-86400000)
110.}
111.function Date.prototype.toString(){
112.return this.getFullYear()+"-"+(this.getMonth()+1)+"-"+this.getDate
113.
114.();
115.}
116.function setDate(num){
117.if(num==1){
118.document.all.dateDate.value=showMonthFirstDay();
119.document.all.dateDate2.value=showMonthLastDay();
120.}
121.if(num==2){
122.document.all.dateDate.value=showWeekFirstDay();
123.document.all.dateDate2.value=showWeekLastDay();
124.}
125.if(num==3){
126.document.all.dateDate.value=showToDay();
127.document.all.dateDate2.value=showToDay();
128.}
129.if(num==4){
130.document.all.dateDate.value=showPreviousFirstDay();
131.document.all.dateDate2.value=showPreviousLastDay();
132.}
133.if(num==5){
134.document.all.dateDate.value=showNextFirstDay();
135.document.all.dateDate2.value=showNextLastDay();
136.}
137.if(num==6){
138.document.all.dateDate.value=showPreviousFirstWeekDay();
139.document.all.dateDate2.value=showPreviousLastWeekDay();
140.}
141.if(num==7){
142.document.all.dateDate.value=showNextFirstWeekDay();
143.document.all.dateDate2.value=showNextLastWeekDay();
144.}
145.if(num==8){
146.document.all.dateDate.value=showPreviousDay();
147.document.all.dateDate2.value=showPreviousDay();
148.}
149.if(num==9){
150.document.all.dateDate.value=showNextDay();
151.document.all.dateDate2.value=showNextDay();
152.}
153.}
154.
155.
// --></mce:script>
156.<input name=dateDate type=text>-><input name=dateDate2 type=text>
157. <input name=haha type=button value="上一月" οnclick=setDate
158.
159.(4)>
160. <input name=haha type=button value="本月" οnclick=setDate(1)
161.
162.>
163.<input name=haha type=button value="下一月" οnclick=setDate(5)
164.
165.>
166.<input name=haha type=button value="上一周" οnclick=setDate(6)
167.
168.>
169.<input name=haha type=button value="本周" οnclick=setDate(2)>
170.<input name=haha type=button value="下一周" οnclick=setDate(7)
171.
172.>
173.<input name=haha type=button value="上一天" οnclick=setDate(8)
174.
175.>
176.<input name=haha type=button value="今天" οnclick=setDate(3)>
177.<input name=haha type=button value="下一天" οnclick=setDate(9)>
自己写的:
/*
* 求某年某月的总天数
*/
function getDates(year, month) {
var now2 = new Date(year, month, 0); // 这是本月的最后一天
return now2.getDate();
}
/*
* 获取某年某月1号的星期序号
*/
function getFirstDay(year, month) {
var now = new Date(year, month - 1, 1);
var day = now.getDay();
if (day == 0)
return 7;
else {
return day;
}
}
/*
* 求某年某月星期的总数
*/
function getDays(year, month) {
if (getDates(year, month) - 28 +getFirstDay(year,month) > 8)
return 6;
if (getDates(year, month) == 28
&& getFirstDay(year, month) == 1)
return 4;
else
return 5;
}
其他文章中转来的
1.<mce:script language=javascript><!--
2.//一天含 86,400,000 毫秒(24* 60 * 60*1000)
3.
4.//今天
5.function showToDay()
6.{
7.var Nowdate=new Date();
8.M=Number(Nowdate.getMonth())+1
9.return Nowdate.getYear()+"-"+M+"-"+Nowdate.getDate();
10.}
11.
12.//本周第一天
13.function showWeekFirstDay()
14.{
15.var Nowdate=new Date();
16.var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
17.return WeekFirstDay;
18.}
19.//本周最后一天
20.function showWeekLastDay()
21.{
22.var Nowdate=new Date();
23.var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
24.var WeekLastDay=new Date((WeekFirstDay/1000+6*86400)*1000);
25.return WeekLastDay;
26.}
27.
28.//本月第一天
29.function showMonthFirstDay()
30.{
31.var Nowdate=new Date();
32.var MonthFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth(),1);
33.return MonthFirstDay;
34.}
35.//本月最后一天
36.function showMonthLastDay()
37.{
38.var Nowdate=new Date();
39.var MonthNextFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth
40.
41.()+1,1);
42.var MonthLastDay=new Date(MonthNextFirstDay-86400000);
43.return MonthLastDay;
44.}
45.//上月第一天
46.function showPreviousFirstDay()
47.{
48.var MonthFirstDay=showMonthFirstDay()
49.return new Date(MonthFirstDay.getYear(),MonthFirstDay.getMonth()-
50.
51.1,1)
52.}
53.//上月最后一天
54.function showPreviousLastDay()
55.{
56.var MonthFirstDay=showMonthFirstDay();
57.return new Date(MonthFirstDay-86400000);
58.}
59.//上周第一天
60.function showPreviousFirstWeekDay()
61.{
62.var WeekFirstDay=showWeekFirstDay()
63.return new Date(WeekFirstDay-86400000*7)
64.}
65.//上周最后一天
66.function showPreviousLastWeekDay()
67.{
68.var WeekFirstDay=showWeekFirstDay()
69.return new Date(WeekFirstDay-86400000)
70.}
71.//上一天
72.function showPreviousDay()
73.{
74.var MonthFirstDay=new Date();
75.return new Date(MonthFirstDay-86400000);
76.}
77.//下一天
78.function showNextDay()
79.{
80.var MonthFirstDay=new Date();
81.return new Date((MonthFirstDay/1000+86400)*1000);
82.}
83.//下周第一天
84.function showNextFirstWeekDay()
85.{
86.var MonthFirstDay=showWeekLastDay()
87.return new Date((MonthFirstDay/1000+86400)*1000)
88.}
89.//下周最后一天
90.function showNextLastWeekDay()
91.{
92.var MonthFirstDay=showWeekLastDay()
93.return new Date((MonthFirstDay/1000+7*86400)*1000)
94.}
95.//下月第一天
96.function showNextFirstDay()
97.{
98.var MonthFirstDay=showMonthFirstDay()
99.return new Date(MonthFirstDay.getYear(),MonthFirstDay.getMonth()
100.
101.+1,1)
102.}
103.//下月最后一天
104.function showNextLastDay()
105.{
106.var MonthFirstDay=showMonthFirstDay()
107.return new Date(new Date(MonthFirstDay.getYear
108.
109.(),MonthFirstDay.getMonth()+2,1)-86400000)
110.}
111.function Date.prototype.toString(){
112.return this.getFullYear()+"-"+(this.getMonth()+1)+"-"+this.getDate
113.
114.();
115.}
116.function setDate(num){
117.if(num==1){
118.document.all.dateDate.value=showMonthFirstDay();
119.document.all.dateDate2.value=showMonthLastDay();
120.}
121.if(num==2){
122.document.all.dateDate.value=showWeekFirstDay();
123.document.all.dateDate2.value=showWeekLastDay();
124.}
125.if(num==3){
126.document.all.dateDate.value=showToDay();
127.document.all.dateDate2.value=showToDay();
128.}
129.if(num==4){
130.document.all.dateDate.value=showPreviousFirstDay();
131.document.all.dateDate2.value=showPreviousLastDay();
132.}
133.if(num==5){
134.document.all.dateDate.value=showNextFirstDay();
135.document.all.dateDate2.value=showNextLastDay();
136.}
137.if(num==6){
138.document.all.dateDate.value=showPreviousFirstWeekDay();
139.document.all.dateDate2.value=showPreviousLastWeekDay();
140.}
141.if(num==7){
142.document.all.dateDate.value=showNextFirstWeekDay();
143.document.all.dateDate2.value=showNextLastWeekDay();
144.}
145.if(num==8){
146.document.all.dateDate.value=showPreviousDay();
147.document.all.dateDate2.value=showPreviousDay();
148.}
149.if(num==9){
150.document.all.dateDate.value=showNextDay();
151.document.all.dateDate2.value=showNextDay();
152.}
153.}
154.
155.
// --></mce:script>
156.<input name=dateDate type=text>-><input name=dateDate2 type=text>
157. <input name=haha type=button value="上一月" οnclick=setDate
158.
159.(4)>
160. <input name=haha type=button value="本月" οnclick=setDate(1)
161.
162.>
163.<input name=haha type=button value="下一月" οnclick=setDate(5)
164.
165.>
166.<input name=haha type=button value="上一周" οnclick=setDate(6)
167.
168.>
169.<input name=haha type=button value="本周" οnclick=setDate(2)>
170.<input name=haha type=button value="下一周" οnclick=setDate(7)
171.
172.>
173.<input name=haha type=button value="上一天" οnclick=setDate(8)
174.
175.>
176.<input name=haha type=button value="今天" οnclick=setDate(3)>
177.<input name=haha type=button value="下一天" οnclick=setDate(9)>