VBScript:
<script language="vbscript">
date1 = #2008-01-01#
for i=0 to 365
date2 = DateAdd("d",i,date1)
document.write(date2 & " ")
date3 = DateAdd("m",1,date2)
document.write(date3 & " ")
document.write("<font color=red>" & DateDiff("d",date2,date3) & "</font><br/>")
next
</script>JavaScript:
<script language="javascript">
var date = new Date(2008,0,1);
for(var i=0;i<=365;i++){
if(i>0)date = new Date(date.setDate(date.getDate() + 1));
document.write(date.toLocaleDateString() + " ");
var date1 = new Date(date.getTime());
var date2 = new Date(date1.setMonth(date1.getMonth() + 1));
document.write(date2.toLocaleDateString() + " ");
document.write("<font color=red>" + (date2.getTime() - date.getTime())/1000/60/60/24 + "</font><br/>");
}
</script>从例子中我们可以看出:
1.对于VBScript,大部分情况是将当前日期加上当月最大天数,但如果相加的结果不是一个正确的日期(如2月30日),VBScript则相加的天数进行相应的减少,直到下个月的最后一天为止;
2008-1-28 2008-2-28 31
2008-1-29 2008-2-29 31
2008-1-30 2008-2-29 30
2008-1-31 2008-2-29 29
2008-2-1 2008-3-1 29
2008-2-2 2008-3-2 29
2.对于JavaScript,全都是将当前日期加上当月最大天数,如果相加的结果不是一个正确的日期,JavaScript将转换成下下月的日期(如闰年2月30日自动转成3月1日);
2008年1月28日 2008年2月28日 31
2008年1月29日 2008年2月29日 31
2008年1月30日 2008年3月1日 31
2008年1月31日 2008年3月2日 31
2008年2月1日 2008年3月1日 29
2008年2月2日 2008年3月2日 29
评论(0)
暂无评论。