// 不输入参数调用的就是当前时间// 参数--需转换时间的时间戳function formatDate(time = new Date()) {let date = new Date(time);let YY = date.getFullYear();let MM = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;let DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();let hh = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();let mm = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();let ss = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();// 这里修改返回时间的格式return YY + "-" + MM + "-" + DD + " " + hh + ":" + mm + ":" + ss;}
推荐使用:moment:/ 针对时间方面的功能很齐全,而且支持多端适配(例如IOS)