<script>
//当天
function showToDay()
{
var Nowdate=new Date();
M=Number(Nowdate.getMonth())+1
return Nowdate.getYear()+"-"+M+"-"+Nowdate.getDate();
}
//本周第一天
function showWeekFirstDay()
{
var Nowdate=new Date();
var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
return 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);
return WeekLastDay;
}
//本月第一天
function showMonthFirstDay()
{
var Nowdate=new Date();
var MonthFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth(),1);
return MonthFirstDay;
}
//本月最后一天
function showMonthLastDay()
{
var Nowdate=new Date();
var tmpDate=new Date(Nowdate.getYear(),Nowdate.getMonth()+1,1);
//tmpDate.setDate(tmpDate.getDate() -1);
//return new Date(Nowdate.getYear(),Nowdate.getMonth(),tmpDate.getDate());
var MonthLastDay=new Date(tmpDate-86400000);
return MonthLastDay;
}
//本季第一天
function showquarterFirstDay()
{
var Nowdate=new Date();
if(Nowdate.getMonth()<3)
return new Date(Nowdate.getYear(),0,1);
else if(Nowdate.getMonth()>2 && Nowdate.getMonth()<6)
return new Date(Nowdate.getYear(),3,1);
else if(Nowdate.getMonth()>5 && Nowdate.getMonth()<9)
return new Date(Nowdate.getYear(),6,1);
else if(Nowdate.getMonth()>8)
return new Date(Nowdate.getYear(),9,1);
}
//本季最后一天
function showquarterLastDay()
{
var Nowdate=new Date();
if(Nowdate.getMonth()<3)
return new Date(Nowdate.getYear(),2,31);
else if(Nowdate.getMonth()>2 && Nowdate.getMonth()<6)
return new Date(Nowdate.getYear(),5,30);
else if(Nowdate.getMonth()>5 && Nowdate.getMonth()<9)
return new Date(Nowdate.getYear(),8,30);
else if(Nowdate.getMonth()>8)
return new Date(Nowdate.getYear(),11,31);
}
//本年第一天
function showyearFirstDay()
{
var Nowdate=new Date();
var yearFirstDay=new Date(Nowdate.getYear(),0,1);
return yearFirstDay;
}
//本年最后一天
function showyearLastDay()
{
var Nowdate=new Date();
var yearLastDay=new Date(Nowdate.getYear(),11,31);
return yearLastDay;
}
//当前月
function showmonthCurrent()
{
var Nowdate=new Date();
var Month=Nowdate.getMonth()+1;
Month=(Month<10)?'-0'+Month:'-'+Month;
return Nowdate.getYear()+Month;
}
//本季开始年月
function showquarterFirstMonth()
{
var Nowdate=new Date();
if(Nowdate.getMonth()<3)
return Nowdate.getYear()+'-01';
else if(Nowdate.getMonth()>2 && Nowdate.getMonth()<6)
return Nowdate.getYear()+'-04';
else if(Nowdate.getMonth()>5 && Nowdate.getMonth()<9)
return Nowdate.getYear()+'-07';
else if(Nowdate.getMonth()>8)
return Nowdate.getYear()+'-10';
}
//本季最后年月
function showquarterLastMonth()
{
var Nowdate=new Date();
if(Nowdate.getMonth()<3)
return Nowdate.getYear()+'-03';
else if(Nowdate.getMonth()>2 && Nowdate.getMonth()<6)
return Nowdate.getYear()+'-06';
else if(Nowdate.getMonth()>5 && Nowdate.getMonth()<9)
return Nowdate.getYear()+'-09';
else if(Nowdate.getMonth()>8)
return Nowdate.getYear()+'-12';
}
//本年开始年月
function showyearFirstMonth()
{
var Nowdate=new Date();
return Nowdate.getYear()+'-01';
}
//本年最后年月
function showyearLastMonth()
{
var Nowdate=new Date();
return Nowdate.getYear()+'-12';
}
//格式化日期格式
function Date.prototype.toString(){
return this.getFullYear()+"-"+(this.getMonth()+1)+"-"+this.getDate();
}
</script>
javascript日期函数大全
最新推荐文章于 2024-01-03 17:05:03 发布