function ktkGetNextMonth(currentDate, scaleStep) {
//scaleStep = 1 向后计算后一个月
//scaleStep = -1 向前计算前一个月
for(var minIncrements = 1;; minIncrements++) {
var nextDate = new Date(currentDate);
nextDate.setHours(currentDate.getHours() + scaleStep * minIncrements);
if(nextDate.getMonth() != currentDate.getMonth()) {
return nextDate;
}
}
}
function ktkGetNextDate(currentDate, scaleStep) {
//scaleStep = 1 向后计算后一天
//scaleStep = -1 向前计算前一天
for(var minIncrements = 1;; minIncrements++) {
var nextDate = new Date(currentDate);
nextDate.setHours(currentDate.getHours() + scaleStep * minIncrements);
if(nextDate.getDate() != currentDate.getDate()) {
return nextDate;
}
}
}
JS计算前一天或后一天等
最新推荐文章于 2024-03-04 15:03:16 发布