【发布时间】:2016-04-28 08:55:34
【问题描述】:
我想要一些如何打印消息,例如: “从那时起,已经过去了 x 天、y 小时、z 分钟和 w 秒”。 目前我正在做这样的事情,但我想念其余部分加上(最重要的是)我不喜欢它。应该有更美的东西
dt = (datetime.now() - datetime(year=1980, month=1, day=1, hour=18)).total_seconds()
full_days = int(dt // (3600 * 24))
full_hours = int((dt - full_days * (24 * 3600)) // 3600)
full_minutes = int((dt - full_days * (24 * 3600) - full_hours * 3600) // 60)
residual_seconds = dt - full_days * (24 * 3600) - full_hours * 3600 - full_minutes * 60
print(full_days, full_hours, full_minutes, residual_seconds)
【问题讨论】: