python将时间戳转化为几天几个小时几分钟几秒

def hanshu(time):
m,s=divmod(time,60)
h,m=divmod(m,60)
d,h=divmod(h,24)
print("%d天%d小时%d分钟%d秒"%(d,h,m,s))
time=int(input(“请输入一个秒数:”))
hanshu(time)
运行结果
关于divmod函数的解释:
divmod(参数a,参数b) 返回的结果是(a//b,a%b)

猜你喜欢

转载自blog.csdn.net/weixin_41478121/article/details/88697710