from datetime import datetime, timedelta
import time
clear_recycle = 1
delete_time = 1619424497000
local_time = int(1000 * time.time())
tobe_delete_time = delete_time + 1000 * 3600 * 24 * clear_recycle
# 计算剩余清理时间,单位:秒
left_seconds = int((tobe_delete_time - local_time) / 1000)
time = datetime(1,1,1) + timedelta(seconds=left_seconds)
# 格式化时间
month, day, hour, minute = "", "", "", ""
if time.month - 1 > 0:
month = f"{time.month - 1}月"
if time.day - 1 > 0:
day = f"{time.day - 1}天"
if time.hour:
hour = f"{time.hour}小时"
if time.minute:
minute = f"{time.minute}分"
left_seconds_format = f"{month}{day}{hour}{minute}"
print(left_seconds_format)
[python] 给定时间计算月时分
最新推荐文章于 2022-02-12 12:18:37 发布