(time, option)
| 57 | * @returns {string} |
| 58 | */ |
| 59 | export function formatTime(time, option) { |
| 60 | if (('' + time).length === 10) { |
| 61 | time = parseInt(time) * 1000 |
| 62 | } else { |
| 63 | time = +time |
| 64 | } |
| 65 | const d = new Date(time) |
| 66 | const now = Date.now() |
| 67 | |
| 68 | const diff = (now - d) / 1000 |
| 69 | |
| 70 | if (diff < 30) { |
| 71 | return '刚刚' |
| 72 | } else if (diff < 3600) { |
| 73 | // less 1 hour |
| 74 | return Math.ceil(diff / 60) + '分钟前' |
| 75 | } else if (diff < 3600 * 24) { |
| 76 | return Math.ceil(diff / 3600) + '小时前' |
| 77 | } else if (diff < 3600 * 24 * 2) { |
| 78 | return '1天前' |
| 79 | } |
| 80 | if (option) { |
| 81 | return parseTime(time, option) |
| 82 | } else { |
| 83 | return ( |
| 84 | d.getMonth() + |
| 85 | 1 + |
| 86 | '月' + |
| 87 | d.getDate() + |
| 88 | '日' + |
| 89 | d.getHours() + |
| 90 | '时' + |
| 91 | d.getMinutes() + |
| 92 | '分' |
| 93 | ) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @param {string} url |
no test coverage detected