格式化运行时长。
(total_seconds: int)
| 59 | |
| 60 | |
| 61 | def format_uptime(total_seconds: int) -> str: |
| 62 | """格式化运行时长。""" |
| 63 | total_seconds = max(0, int(total_seconds)) |
| 64 | days, remainder = divmod(total_seconds, 86400) |
| 65 | hours, remainder = divmod(remainder, 3600) |
| 66 | minutes, seconds = divmod(remainder, 60) |
| 67 | |
| 68 | parts = [] |
| 69 | if days: |
| 70 | parts.append(f"{days}天") |
| 71 | if days or hours: |
| 72 | parts.append(f"{hours}小时") |
| 73 | if days or hours or minutes: |
| 74 | parts.append(f"{minutes}分钟") |
| 75 | parts.append(f"{seconds}秒") |
| 76 | |
| 77 | return " ".join(parts) |
| 78 | |
| 79 | |
| 80 | def get_process_uptime() -> str: |
no outgoing calls