Call
Settimerange (2);
function Settimerange (v) {
var FMT = ' Yyyy-mm-dd hh:mm ';
var now = new Date ();
var end = new Date ();
if (v = = 0) {
} else if (v = = 1) {
} else if (v = = 2) {
Yesterday
Now.setdate (now.getdate ()-1);
End.setdate (end.getdate ()-1);
} else if (v = = 3) {
Week
var Nowdayofweek = Now.getday (); The day of the week today
if (nowdayofweek = = 0) {
Nowdayofweek = 6;//sunday
} else {
Nowdayofweek = nowDayOfWeek-1;
}
Now.setdate (now.getdate ()-nowdayofweek);
End.setdate (now.getdate () + 6);
} else if (v = = 4) {
Last week
var Nowdayofweek = Now.getday (); The day of the week today
if (nowdayofweek = = 0) {
Nowdayofweek = 6;//sunday
} else {
Nowdayofweek = nowDayOfWeek-1;
}
Now.setdate (now.getdate ()-nowDayOfWeek-7);
End.setdate (now.getdate () + 6);
} else if (v = = 5) {
Month
Now.setdate (1);
var nextmonth = End.getmonth () + 1;
var nextmonthfirstday=new Date (end.getfullyear (), nextmonth,1);
var oneday= 1000 * 60 * 60 * 24;
end = new Date (nextmonthfirstday-oneday);
} else if (v = = 6) {
Last month
var nextmonth = Now.getmonth ()-1;
Now.setmonth (nextmonth);
Now.setdate (1);
Nextmonth = Nextmonth + 1;
var nextmonthfirstday= new Date (end.getfullyear (), nextmonth, 1);
var oneday= 1000 * 60 * 60 * 24;
end = new Date (nextmonthfirstday-oneday);
}
Now.sethours (0);
Now.setminutes (0);
Now.setseconds (0);
End.sethours (23);
End.setminutes (59);
End.setseconds (59);
Let's print this out here.
Console.log (now + ': ' + end);
}
JS time to get the day, yesterday, this week, last week, this month, last month