| 24 | } |
| 25 | |
| 26 | export function formatTime(timestamp: string) { |
| 27 | const date = new Date(timestamp) |
| 28 | const now = new Date() |
| 29 | const diff = now.getTime() - date.getTime() |
| 30 | const seconds = Math.floor(diff / 1000) |
| 31 | const minutes = Math.floor(seconds / 60) |
| 32 | const hours = Math.floor(minutes / 60) |
| 33 | const days = Math.floor(hours / 24) |
| 34 | const months = Math.floor(days / 30) |
| 35 | if (months > 1) { |
| 36 | return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}` |
| 37 | } else if (days > 0) { |
| 38 | return `${days}d` |
| 39 | } else if (hours > 0) { |
| 40 | return `${hours}h` |
| 41 | } else if (minutes > 0) { |
| 42 | return `${minutes}m` |
| 43 | } else { |
| 44 | return `${seconds}s` |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | export function formatDate(date: string) { |
| 49 | const d = new Date(date) |