Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 UTC 时间戳,我想用 Python 计算从那时到现在的小时数。我怎样才能做到这一点?
谢谢!
datetime是此处使用的模块(由于 UTC 要求):
datetime
def hours_since(timestamp): import datetime return (datetime.datetime.utcnow() - datetime.datetime.utcfromtimestamp(timestamp)).total_seconds() / 3600.
例子:
hours_since(1385715744.206451) 0.18432851777777778