用python转换Mac时间戳 [英] Convert Mac Timestamps with python
本文介绍了用python转换Mac时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用python(在linux系统上)将Mac OSX(HFS Plus)时间戳转换为人类可读格式。
I am trying to convert Mac OSX (HFS Plus) timestamps to human readable format with python (on a linux system).
HFS Plus时间戳表示时间
HFS Plus timestamps represent the time in seconds since midnight Jan 1, 1904.
例如,时间戳: 3453120824
在人类日期时间:星期一,2013年6月03日16:13:44 GMT
有没有一个python的方式来做这个? / p>
Is there a python way to do this?
推荐答案
如何使用 datetime , timedelta ?您需要特别注意格式化字符列表这里
How about just using datetime with timedelta? You'll want to pay particular attention to the list of formatting characters here
>>> import datetime
>>> d = datetime.datetime.strptime("01-01-1904", "%m-%d-%Y")
>>> d
datetime.datetime(1904, 1, 1, 0, 0)
>>> d + datetime.timedelta(seconds=3453120824)
datetime.datetime(2013, 6, 3, 16, 13, 44)
>>> (d + datetime.timedelta(seconds=3453120824)).strftime("%a, %d %b %Y %H:%M:%S GMT")
'Mon, 03 Jun 2013 16:13:44 GMT'
这篇关于用python转换Mac时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文