123456789101112131415161718192021222324252627282930313233343536 |
- export default{
- // 时间戳转换成日期
- formatDate(DateNum, AccurateTo) {
- var date = new Date(DateNum)
- var returnValue = ''
- var Y = date.getFullYear()
- var M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
- var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
- var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
- var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
- var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
- switch (AccurateTo) {
- case 'Y':
- returnValue = Y
- break
- case 'M':
- returnValue = Y + '-' + M
- break
- case 'D':
- returnValue = Y + '-' + M + '-' + D
- break
- case 'h':
- returnValue = Y + '-' + M + '-' + D + ' ' + h
- break
- case 'm':
- returnValue = Y + '-' + M + '-' + D + ' ' + h + ':' + m
- break
- case 's':
- returnValue = Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + s
- break
- default:
- returnValue = Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + s
- }
- return returnValue
- },
- }
|