首页 > 代码库 > JavaScript获取当前日期,和N天后的日期

JavaScript获取当前日期,和N天后的日期

//日历插件设置初始值;当前日期和30天后日期;
function getNowDate(){
    var nowDate = new Date();
    var nowY = nowDate.getFullYear();
    var nowM = nowDate.getMonth()+1;
    var nowD = nowDate.getDate();
    var nowDateStr = nowY+"-"+(nowM<10 ? "0" + nowM : nowM)+"-"+(nowD<10 ? "0"+ nowD : nowD);
    return nowDateStr;
}
function getH30Date(){
    var h30Date = new Date();
    h30Date.setDate(h30Date.getDate()+30);
    var lastY = h30Date.getFullYear();
    var lastM = h30Date.getMonth()+1;
    var lastD = h30Date.getDate();
    var h30DateStr=lastY+"-"+(lastM<10 ? "0" + lastM : lastM)+"-"+(lastD<10 ? "0"+ lastD : lastD);
    return h30DateStr;
}

 

JavaScript获取当前日期,和N天后的日期