//formatDate(date, "yyyy-MM-dd hh:mm:ss") // 使用方法 export function formatDate(date, fmt) { if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) } let o = { 'M+': date.getMonth() + 1, 'd+': date.getDate(), 'h+': date.getHours(), 'm+': date.getMinutes(), 's+': date.getSeconds() } for (let k in o) { if (new RegExp(`(${k})`).test(fmt)) { let str = o[k] + '' fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str)) } } return fmt } function padLeftZero(str) { return ('00' + str).substr(str.length) } export function showTime() { let show_day = new Array('星期一','星期二','星期三','星期四','星期五','星期六','星期日') let time = new Date() let year = time.getFullYear() let month = time.getMonth() + 1 let date = time.getDate() let day = time.getDay() let hour = time.getHours() let minutes = time.getMinutes() let second = time.getSeconds() month < 10 ? month = '0' + month : month hour < 10 ? hour = '0' + hour : hour minutes < 10 ? minutes = '0' + minutes : minutes second < 10 ? second = '0' + second : second; return year+'年 '+month+'月 '+date+'日 '+' '+show_day[day-1]+' '+hour+':'+minutes+':'+second }