Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Mac Timestamps with python

I am trying to convert Mac OSX (HFS Plus) timestamps to human readable format with python (on a linux system).

HFS Plus timestamps represent the time in seconds since midnight Jan 1, 1904.

For example, the timestamp: 3453120824

In human date time: Mon, 03 Jun 2013 16:13:44 GMT

Is there a python way to do this?

like image 506
user2448592 Avatar asked Jun 03 '13 16:06

user2448592


1 Answers

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'
like image 102
sberry Avatar answered Sep 30 '22 10:09

sberry