某个时间周期的头天或尾天
Posted 栖息地
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了某个时间周期的头天或尾天相关的知识,希望对你有一定的参考价值。
//本周的第一天
weekFirstDay: function (date) {
var Nowdate = new Date(date);
var WeekFirstDay = new Date(Nowdate - (Nowdate.getDay() - 1) * 86400000);
M = Number(WeekFirstDay.getMonth()) + 1
M = M < 10 ? "0" + M : M;
return WeekFirstDay.getFullYear() + "-" + M + "-" + WeekFirstDay.getDate();
},
//本周的最后一天
weekLastDay: function (date) {
var Nowdate = new Date(date);
var WeekFirstDay = new Date(Nowdate - (Nowdate.getDay() - 1) * 86400000);
var WeekLastDay = new Date((WeekFirstDay / 1000 + 6 * 86400) * 1000);
M = Number(WeekLastDay.getMonth()) + 1
M = M < 10 ? "0" + M : M;
return WeekLastDay.getFullYear() + "-" + M + "-" + WeekLastDay.getDate();
},
//本月第一天
monthFirstDay: function () {
var Nowdate = new Date();
var MonthFirstDay = new Date(Nowdate.getFullYear(), Nowdate.getMonth(), 1);
M = Number(MonthFirstDay.getMonth()) + 1
M = M < 10 ? "0" + M : M;
return MonthFirstDay.getFullYear() + "-" + M + "-" + MonthFirstDay.getDate();
},
//本月最后一天
monthLastDay: function () {
var Nowdate = new Date();
var MonthNextFirstDay = new Date(Nowdate.getFullYear(), Nowdate.getMonth() + 1, 1);
var MonthLastDay = new Date(MonthNextFirstDay - 86400000);
M = Number(MonthLastDay.getMonth()) + 1
M = M < 10 ? "0" + M : M;
return MonthLastDay.getFullYear() + "-" + M + "-" + MonthLastDay.getDate();
},
//上个月第一天
upMonthFirstDay: function () {
var nowdays = new Date();
var year = nowdays.getFullYear();
var month = nowdays.getMonth();
if (month == 0) {
month = 12;
year = year - 1;
}
if (month < 10) {
month = "0" + month;
}
return year + "-" + month + "-" + "01";//上个月的第一天
},
//上个月最后一天
upMonthLastDay: function () {
var nowdays = new Date();
var year = nowdays.getFullYear();
var month = nowdays.getMonth();
if (month == 0) {
month = 12;
year = year - 1;
}
if (month < 10) {
month = "0" + month;
}
//return year + "-" + month + "-" + "01";//上个月的第一天
var myDate = new Date(year, month, 0);
return year + "-" + month + "-" + myDate.getDate();//上个月的最
}
以上是关于某个时间周期的头天或尾天的主要内容,如果未能解决你的问题,请参考以下文章