JavaScript记录一下

JS为时间添加天数,格式化天数方法记录一下:

​
// 添加天数
function addDay(dayNumber, date) {
    var ms = dayNumber * (1000 * 60 * 60 * 24)
    var newDate = new Date(date.getTime() + ms);
    return newDate;
}

// 获取格式化后的日期
function getNowFormatDate(date) {
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
}

​
发布了276 篇原创文章 · 获赞 200 · 访问量 72万+

猜你喜欢

转载自blog.csdn.net/u012561176/article/details/89702931