js获取日期时间

获取当前时间

function getNowFormatDate() {//获取当前时间
    var date = new Date();
    var symbol_gang = "-";
    var symbol_maohao = ":";
    var strMonth = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var strDay = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    var strHours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    var strMinutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    var strSeconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    var currentdate = date.getFullYear() + symbol_gang + strMonth + symbol_gang + strDay
        + " " + strHours + symbol_maohao + strMinutes
        + symbol_maohao + strSeconds;
    return currentdate;
}

获取明天

function getTomorrow() {
    var date = new Date();
    date.setTime(date.getTime() + 24 * 60 * 60 * 1000);
    var strMonth = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var strDay = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    var tomorrow = date.getFullYear() + "-" + strMonth + "-" + strDay;
    return tomorrow;
}
posted @ 2019-08-06 11:44  TBHacker  阅读(569)  评论(0编辑  收藏  举报