JS获取当前时间(yyyy/MM/dd HH:mm:SS)

//取得系统日期
function nowDatetime() {
 
    var date = new Date();
    var month = (date.getMonth()+1) > 9 ? (date.getMonth()+1) : "0" + (date.getMonth()+1);
    var day = (date.getDate()) > 9 ? (date.getDate()) : "0" + (date.getDate());
    var hours = (date.getHours()) > 9 ? (date.getHours()) : "0" + (date.getHours());
    var minutes = (date.getMinutes()) > 9 ? (date.getMinutes()) : "0" + (date.getMinutes());
    var seconds = (date.getSeconds()) > 9 ? (date.getSeconds()) : "0" + (date.getSeconds());
     
    var dateString =
        date.getFullYear() + "/" +
        month + "/" +
        day + " " +
        hours + ":" +
        minutes + ":" +
        seconds;
         
    return dateString; 
}

运行结果:

2019/01/18 14:07:03

猜你喜欢

转载自blog.csdn.net/weixin_44566738/article/details/86538973