Javascrip获取当前月第一天、最后一天,本周第一天、最后一天

<script   language=javascript> 
function   showWeekFirstDay() 
{ 
var   Nowdate=new   Date(); 
var   WeekFirstDay=new   Date(Nowdate-(Nowdate.getDay()-1)*86400000); 
alert(WeekFirstDay) 
} 
function   showWeekLastDay() 
{ 
var   Nowdate=new   Date(); 
var   WeekFirstDay=new   Date(Nowdate-(Nowdate.getDay()-1)*86400000); 
var   WeekLastDay=new   Date((WeekFirstDay/1000+6*86400)*1000); 
alert(WeekLastDay) 
} 
function   showMonthFirstDay() 
{ 
var   Nowdate=new   Date(); 
var   MonthFirstDay=new   Date(Nowdate.getYear(),Nowdate.getMonth(),1); 
alert(MonthFirstDay) 
} 
function   showMonthLastDay() 
{ 
var   Nowdate=new   Date(); 
var   MonthNextFirstDay=new   Date(Nowdate.getYear(),Nowdate.getMonth()+1,1); 
var   MonthLastDay=new   Date(MonthNextFirstDay-86400000); 
alert(MonthLastDay) 
} 
</script> 
<input   name=haha   type=button   value= "本周第一天 "   onclick=showWeekFirstDay()> 
<input   name=haha   type=button   value= "本周第七天 "   onclick=showWeekLastDay()> 
<input   name=haha   type=button   value= "本月第一天 "   onclick=showMonthFirstDay()> 
<input   name=haha   type=button   value= "本月最后一天 "   onclick=showMonthLastDay()>
 

你可能感兴趣的:(JavaScript,Date,script)