首页 > 其他分享 >2022-11-18 js 获取当前时间 格式为“yyyy-MM-dd HH:MM:SS”

2022-11-18 js 获取当前时间 格式为“yyyy-MM-dd HH:MM:SS”

时间:2022-11-18 16:16:04浏览次数:59  
标签:11 MM dd month yyyy SS HH var

    // 获取当前时间 格式为“yyyy-MM-dd HH:MM:SS”
    getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
            + " " + date.getHours() + seperator2 + date.getMinutes()
            + seperator2 + date.getSeconds();
        return currentdate;
    }

 

标签:11,MM,dd,month,yyyy,SS,HH,var
From: https://www.cnblogs.com/iuniko/p/16903561.html

相关文章