【发布时间】:2014-12-04 07:03:48
【问题描述】:
最初我编写这段代码是为了将日期转换为人类可读的时间:
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
【问题讨论】:
-
@JohnZwinck 不,问题没有回答,如果我从 last_epoch - time.time() 转换秒数,我将得到 1970 年
-
恕我直言,更接近的副本是这个:stackoverflow.com/questions/6574329/…