js获取当前时间(yyyy-MM-dd hh:mm:ss)

function getNowDateFormate() {
    var myDate = new Date();
    var years = myDate.getFullYear();
    var month = add_zero(myDate.getMonth() + 1);
    var day = add_zero(myDate.getDate());
    var hours = add_zero(myDate.getHours());
    var minutes = add_zero(myDate.getMinutes());
    var seconds = add_zero(myDate.getSeconds());
    var datetime = years + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
    return datetime;
}

function add_zero(temp) {
    if (temp < 10) return "0" + temp;
    else return temp;
}

//调用

$(funaction(){

var datatime = getNowDateFormate();

  alert(datatime);

})

原文地址:https://www.cnblogs.com/recent/p/3414319.html