js获得时间(本周,本季度,本月)
JS代码复制代码代码如下所示:
*开始日期,停止日期,本周,本季度,本月,最后一个月。
* /
var现在是新的(日期);当前日期是
var = now.getday(nowdayofweek); / /本周的前几天,今天
var = now.getdate(今天); / /天
var = now.getmonth(nowmonth); / /当月
var = now.getyear(nowyear); / /当年
nowyear =(nowyear<2000)1900:0; / /
无功lastmonthdate =新(日期); / /日期的最后一个月
(1)lastmonthdate.setdate;
lastmonthdate.setmonth(lastmonthdate.getmonth)-(1);
去年lastmonthdate.getyear(VaR)=;
上个月,lastmonthdate.getmonth(VAR);
/ /日期模式:yyyy-mm-dd
功能formatDate(日期){
无功myyear = date.getfullyear();
无功mymonth = date.getmonth()+ 1;
无功myweekday = date.getdate();
如果(mymonth<10){
mymonth =0+ mymonth;
}
如果(myweekday<10){
myweekday =0+ myweekday;
}
返回(+ mymonth +-+ myweekday);
}
获取月日
功能getmonthdays(mymonth){
无功monthstartdate =新的日期(nowyear,mymonth,1);
无功monthenddate =新的日期(nowyear,mymonth + 1, 1);
VaR天=(monthenddate - monthstartdate)/(1000×60×60×24);
回归的日子;
}
在月初/月初
功能getquarterstartmonth(){
无功quarterstartmonth = 0;
如果(nowmonth<3){
quarterstartmonth = 0;
}
如果(2<nowmonth nowmonth<6){
quarterstartmonth = 3;
}
如果(5<nowmonth nowmonth<9){
quarterstartmonth = 6;
}
如果(nowmonth > 8){
quarterstartmonth = 9;
}
返回quarterstartmonth;
}
对于本周的开始日期
功能getweekstartdate(){
无功weekstartdate =新的日期(nowyear,nowmonth,今天- nowdayofweek);
返回formatDate(weekstartdate);
}
本周获取/停止日期
功能getweekenddate(){
无功weekenddate =新的日期(nowyear,nowmonth,今天+(6 - nowdayofweek));
返回formatDate(weekenddate);
}
获取月起始日期
功能getmonthstartdate(){
无功monthstartdate =新的日期(nowyear,nowmonth,1);
返回formatDate(monthstartdate);
}
本月停止约会
功能getmonthenddate(){
无功monthenddate =新的日期(nowyear,nowmonth,getmonthdays(nowmonth));
返回formatDate(monthenddate);
}
上个月开始工作
功能getlastmonthstartdate(){
无功lastmonthstartdate =新的日期(nowyear,上个月,1);
返回formatDate(lastmonthstartdate);
}
上个月获得/停止时间
功能getlastmonthenddate(){
无功lastmonthenddate =新的日期(nowyear,上个月,getmonthdays(上个月));
返回formatDate(lastmonthenddate);
}
开始日期
功能getquarterstartdate(){
无功quarterstartdate =新的日期(nowyear,getquarterstartmonth(),1);
返回formatDate(quarterstartdate);
}
停止/日期或季度。
功能getquarterenddate(){
无功quarterendmonth = getquarterstartmonth()+ 2;
无功quarterstartdate =新的日期(nowyear,quarterendmonth,getmonthdays(quarterendmonth));
返回formatDate(quarterstartdate);
}