js获取指定日期前后的日期代码

时间:2021-05-26

复制代码 代码如下:
function getmonths(dateday){

var curDate = new Date(dateday);
return curDate.getMonth()+1;
};
function getYears(dateday){

var curDate = new Date(dateday);
return curDate.getFullYear();
};
function getCountDays(dateday) {

var curDate = new Date(dateday);

var curMonth = curDate.getMonth();

curDate.setMonth(curMonth + 1);

curDate.setDate(0);

return curDate.getDate();
};

function getBeforeDay(day,amount,isShortTime){
if(Date.parse(day) != Date.parse(day)){
return false;
}
var days = new Date(new Date(day)-1000*60*60*24);
if(amount){
var number = parseInt(amount);
if(number && number > 0 && !isNaN(number)){
days = new Date(new Date(day)-1000*60*60*24*number);
}
}
return dateFormat(days,isShortTime);
}

function getAfterDay(day,amount,isShortTime){
if(Date.parse(day) != Date.parse(day)){
return false;
}
day =new Date(day);
var v = day.valueOf();
var days = new Date((v+86400000));
if(amount){
var number = parseInt(amount);
if(number && number > 0 && !isNaN(number)){
days = new Date((v+86400000*number));
}
}
return dateFormat(days,isShortTime);
}

function dateFormat(day,isShortTime){
if(Date.parse(day) != Date.parse(day)){
return false;
}
var days = new Date(day);
if(isShortTime && isShortTime==true){
var hours = days.getHours()<10?"0"+days.getHours():days.getHours();
var minutes = days.getMinutes()<10?"0"+days.getMinutes():days.getMinutes();
var seconds = days.getSeconds()<10?"0"+days.getSeconds():days.getSeconds();
return days.getFullYear()+"-"+(days.getMonth()+1)+"-"+days.getDate()+" "+hours+":"+minutes+":"+seconds;
}else{
return days.getFullYear()+"-"+(days.getMonth()+1)+"-"+days.getDate();
}
}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章