获取当前时间 年月日时分秒

  var date = new Date();
    var seperator1 = "-";

    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var hour = date.getHours();
    var minutes = date.getMinutes();
    var seconds = date.getSeconds();
    var strDate = date.getDate();

    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    if (hour >= 0 && hour <= 9) {
        hour = "0" + hour;
    }
    if (minutes >= 0 && minutes <= 9) {
        minutes = "0" + minutes;
    }
    if (seconds >= 0 && seconds <= 9) {
        seconds = "0" + seconds;
    }
    var curtimestart =  year + seperator1 + month + seperator1 + strDate  + " " + '00' + ":" + '00' + ":" + '00';
    var curtimeend = year + seperator1 + month + seperator1 + strDate + " " + hour + ":" + minutes + ":" + seconds;

转载于:https://www.cnblogs.com/xzybk/p/11547354.html

posted @ 2021-07-01 09:46  xxshen  阅读(146)  评论(0)    收藏  举报