Python - 将秒从纪元时间转换为人类可读的时间 [英] Python - Convert seconds from epoch time into human readable time
本文介绍了Python - 将秒从纪元时间转换为人类可读的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最初我制作这段代码是为了将日期转换为人类可读的时间:
Originally I made this code to convert date into human readable time:
a = datetime.datetime.strptime(time, "%Y-%m-%d %H:%M:%S.%f")
b = datetime.datetime.now()
c = b - a
days, hours, minutes, seconds = int(c.days), int(c.seconds // 3600), int(c.seconds % 3600 / 60.0), int(c.seconds % 60.0)
return days, hours, minutes, seconds
EXAMPLE OUTPUT: 1 days, 4 hours, 24 minutes, 37 seconds
我正在尝试使用纪元时间,但我不知道让它计算天数等.
and I'm trying to make it using epoch time, but I have no idea on to make it calculate days hours and etc.
a = last_epoch #last epoch recorded
b = time.time() #current epoch time
c = b - a #returns seconds
hours = c // 3600 / 24 #the only thing I managed to figure out
推荐答案
a = last_epoch #last epoch recorded
b = time.time() #current epoch time
c = b - a #returns seconds
days = c // 86400
hours = c // 3600 % 24
minutes = c // 60 % 60
seconds = c % 60
这篇关于Python - 将秒从纪元时间转换为人类可读的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文