如何判断一个月有多少个星期?以及每个月的起始和终结的星期几?

hwoarangzk 2010-09-06 09:07:15
应该从哪里下手?
...全文
1154 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
licip 2010-09-06
  • 打赏
  • 举报
回复
你循环一下,不就什么都有了。这个关键是看每一个月的最后一天。特别是二月
tray123 2010-09-06
  • 打赏
  • 举报
回复
路过!!学习!!!
qqm05 2010-09-06
  • 打赏
  • 举报
回复
<%
Dim a
a=CDate("2010-9-6")

response.write Year(a) & "年" & Month(a) & "月,共有" & days(a) & "天<br>"
response.write Year(a) & "年"&Month(a) & "月,共有" & weeks(a) & "个星期<br>"
write_fl_Weekday a

Function days(d)
days=DateDiff("d",a,Dateadd("m",1,d))
End function
Function weeks(d)
ds=days(d)
If ds Mod 7>0 Then
weeks=Int(ds/7)+1
Else
weeks=Int(ds/7)
End if
End Function
Function write_fl_Weekday(a)
f=CDate(Year(a) & "-" & Month(a) & "-1")
l=DateAdd("d",f,days(a)-1)
response.write "本月第一天("& f &")是:" & WeekDayName(Weekday(f)) & "<br>"
response.write "本月最后一天("& l &")是:" & WeekDayName(Weekday(l)) & "<br>"

End Function
%>
cloudgamer 2010-09-06
  • 打赏
  • 举报
回复
var y = 2010, m = 10;

alert( "星期数" + Math.ceil((new Date(y, m, 0).getDate() + new Date(y, m - 1, 1).getDay()) / 7) );
alert( "开始星期" + new Date(y, m - 1, 1).getDay() );
alert( "结束星期" + new Date(y, m, 0).getDay() );
ACMAIN_CHM 2010-09-06
  • 打赏
  • 举报
回复
getDay(); 判断一下1号和下个月1号的数,然后再天数除7
亥亥 2010-09-06
  • 打赏
  • 举报
回复
asp判断星期比较好
qqm05 2010-09-06
  • 打赏
  • 举报
回复
<%
Dim a,b
a=CDate("2009-9-6")

b=WeekDayName(Weekday(a))
response.write b


%>
mykelly6 2010-09-06
  • 打赏
  • 举报
回复
遍历那个月的每一天,用getDay看每天是星期几,然后各种加减乘除计数器就能得到你的答案了


var myDate = new Date();
myDate.getYear(); //current year(2位)
myDate.getFullYear(); //current full year(4位,1970-now)
myDate.getMonth(); //current month(0-11,0-->1月)
myDate.getDate(); //current day(1-31)
myDate.getDay(); //current weekday(0-6,0-->日曜日)
myDate.getTime(); //current time(Milliseconds form 1970.1.1)
myDate.getHours(); //current hour(0-23)
myDate.getMinutes(); //current minute(0-59)
myDate.getSeconds(); //current second(0-59)
myDate.getMilliseconds(); //current Milliseconds(0-999)
myDate.toLocaleDateString(); //get current date
var mytime=myDate.toLocaleTimeString(); //get current time
myDate.toLocaleString( ); //get current date and time


stayalive 2010-09-06
  • 打赏
  • 举报
回复
getDay
返回值
0 星期天
1 星期一
2 星期二
3 星期三
4 星期四
5 星期五
6 星期六
kslion 2010-09-06
  • 打赏
  • 举报
回复
写了下,供参考:

function YearMonth(year, month) {
this.year = year;
this.month = month;

this.isLeapYear = new Date(year,1,29).getDate() < 29 ? false : true;
}

YearMonth.prototype = {
days:[31,28,31,30,31,30,31,31,30,31,30,31
],
//该月有几天
getDaysCount : function() {
return (this.isLeapYear && this.month==2 ) ? 29 : this.days[this.month-1];
},
//该月有几周
getWeeksCount : function() {
var firstday = new Date(this.year, this.month, 1).getDay();
var firstWeekDays = 6-firstday;
var remainDays = this.getDaysCount()-firstWeekDays;

return Math.ceil(remainDays / 7 + 1);
},
//第一天是周几
getFirstDayInfo : function() {
var first = new Date(this.year, this.month, 1);

return this.getWeek(first.getDay());
},
//最后天是周几
getLastDayInfo : function() {
var last = (this.isLeapYear && this.month==2 ) ? 29 : this.days[month-1];
last = new Date(this.year, this.month, last);

return this.getWeek(first.getDay());
},
//判断周几
getWeek : function(index) {
switch(index) {
case 0 : return 'sun'; break;
case 1 : return 'mon'; break;
case 2 : return 'tue'; break;
case 3 : return 'wed'; break;
case 4 : return 'thu'; break;
case 5 : return 'fri'; break;
case 6 : return 'sat'; break;
default: alert('invalid');
}
}
}

window.onload = function() {

var ym = new YearMonth(2009, 9);
var days = ym.getDaysCount();
var weeks = ym.getWeeksCount();

}
hwoarangzk 2010-09-06
  • 打赏
  • 举报
回复
我试试

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧