function getNowFormatDate() { let date = new Date() let seperator1 = "-" let seperator2 = ":" let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1 let strDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate() let currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds() return currentdate } console.log(getNowFormatDate())//2020-12-25 13:41:41
原文:https://www.cnblogs.com/-roc/p/14188502.html