我收到了三种不同的unixtimes
lastSeen = 1416248381 firstSeen = 1416248157最后一个是lastSeen - firstSeen:
duration = 224现在,我可以将lastSeen和firstSeen转换成日期时间没有问题。 但我在这段时间里遇到了麻烦。
我不确定如何将持续时间转换为分钟/秒等。 有没有人有任何想法,如果这可以做到?
I have received three different unixtimes
lastSeen = 1416248381 firstSeen = 1416248157and the last one is lastSeen - firstSeen:
duration = 224Now, I can convert lastSeen and firstSeen into a datetime no problem. But I am having trouble with the duration.
I am unsure how to convert the duration into something like minutes/seconds. Does anyone have any idea if this can be done?
最满意答案
您需要将秒转换为小时与分钟,并且您可以使用日期时间来完成
import datetime lastSeen = 1416248381 firstSeen = 1416248157 duration = lastSeen - firstSeen str(datetime.timedelta(seconds=duration))输出将是: '0:03:44' : '0:03:44' : '0:03:44'
没有str()函数,你将得到: datetime.timedelta(0, 224)
使用时间
import time time.strftime("%H:%M:%S", time.gmtime(duration))输出将是: '0:03:44' : '0:03:44' : '0:03:44'
You need to convert your seconds to Hours&Minutes and you can do it using datetime
import datetime lastSeen = 1416248381 firstSeen = 1416248157 duration = lastSeen - firstSeen str(datetime.timedelta(seconds=duration))The ouput will be: '0:03:44'
Without the str() function you'll have: datetime.timedelta(0, 224)
Using time
import time time.strftime("%H:%M:%S", time.gmtime(duration))The ouput will be: '0:03:44'
更多推荐
发布评论