| 3 | */ |
| 4 | |
| 5 | export function parseTime(time, cFormat) { |
| 6 | if (arguments.length === 0) { |
| 7 | return null |
| 8 | } |
| 9 | const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}' |
| 10 | let date |
| 11 | if (typeof time === 'object') { |
| 12 | date = time |
| 13 | } else { |
| 14 | if (('' + time).length === 10) time = parseInt(time) * 1000 |
| 15 | date = new Date(time) |
| 16 | } |
| 17 | const formatObj = { |
| 18 | y: date.getFullYear(), |
| 19 | m: date.getMonth() + 1, |
| 20 | d: date.getDate(), |
| 21 | h: date.getHours(), |
| 22 | i: date.getMinutes(), |
| 23 | s: date.getSeconds(), |
| 24 | a: date.getDay() |
| 25 | } |
| 26 | const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { |
| 27 | let value = formatObj[key] |
| 28 | if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1] |
| 29 | if (result.length > 0 && value < 10) { |
| 30 | value = '0' + value |
| 31 | } |
| 32 | return value || 0 |
| 33 | }) |
| 34 | return time_str |
| 35 | } |
| 36 | |
| 37 | export function formatTime(time, option) { |
| 38 | time = +time * 1000 |