最初我编写了这段代码来将日期转换为人类可读的时间:
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
我正在尝试使用纪元时间来实现它,但我不知道如何让它计算天数小时等。
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
import datetime
timestamp = 1339521878.04
value = datetime.datetime.fromtimestamp(timestamp)
print(value.strftime('%Y-%m-%d %H:%M:%S'))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)