formatTimeTwo(number) { var format='Y-M-D h:m:s'; var formateArr = ['Y', 'M', 'D', 'h', 'm', 's']; var returnArr = []; var date = new Date(number * 1000); returnArr.push(date.getFullYear()); returnArr.push(this.formatNumber(date.getMonth() + 1)); returnArr.push(this.formatNumber(date.getDate())); returnArr.push(this.formatNumber(date.getHours())); returnArr.push(this.formatNumber(date.getMinutes())); returnArr.push(this.formatNumber(date.getSeconds())); for (var i in returnArr) { format = format.replace(formateArr[i], returnArr[i]); } return format; }, formatNumber(n) { n = n.toString() return n[1] ? n : '0' + n }
----
时间转时间戳
function formatTime(date) {
var year = date.getFullYear()
var month = date.getMonth() + 1
var day = date.getDate()
var hour = date.getHours()
var minute = date.getMinutes()
var second = date.getSeconds()
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}