js 时间操作

now加n天

//返回yyyy-mm-dd格式
function getLocalTime(addNum) {
    var today, ms, thatDay, y, m, d, endDate;
    today = new Date().getTime();
    ms = today + addNum * 24 * 60 * 60 * 1000;
    thatDay = new Date(ms);
    y = thatDay.getFullYear();
    m = thatDay.getMonth() + 1;
    d = thatDay.getDate();
    endDate = y + "-" + m + "-" + d;
    return endDate
}

获取星期几

//输入yyyy-mm-dd
function getWeekday(sDate) {
    var dt = new Date(sDate.replace(/-/g, '/'));
    var a = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
    return a[dt.getDay()];
}

 

posted @ 2017-12-26 18:40  守y1座_空城  阅读(190)  评论(0编辑  收藏  举报