newDate(0);//当天日期
newDate(-3);//3天前日期
newDate(3);//3天后日期
function newDate(day){
var today = new Date();
var targetday_milliseconds=today.getTime() + 1000*60*60*24*day;
today.setTime(targetday_milliseconds); //注意,这行是关键代码
var tYear = today.getFullYear();
var tMonth = today.getMonth();
var tDate = today.getDate();
tMonth = doHandleMonth(tMonth + 1);
tDate = doHandleMonth(tDate);
return tYear+"-"+tMonth+"-"+tDate;
}
tab('2021-10-10','2021-10-11');
function tab(date1,date2){
var oDate1 = new Date(date1);
var oDate2 = new Date(date2);
if(oDate1.getTime() > oDate2.getTime()){
console.log('第一个大');
} else {
console.log('第二个大');
}
}
js获取当前日期,前几天日期,后几天日期,并比较两个日期大小
于 2022-03-25 09:41:32 首次发布