Search code examples
pythonmacostimestampplistdatestamp

python module to decode OSX plist integer dates?


Is there a python module/snippet which can decode the integer datestamps contained in OSX - specifically mail - plists?

EG, this bit:

<key>date-sent</key>    
<integer>1264001747</integer>

is likely in Jan 2010.

How to deconstruct? I'm aware of the very good plistlib - but this only gets me to that integer.


Solution

  • You can use datetime.datetime.fromtimestamp

    >>> import datetime
    >>> datetime.datetime.fromtimestamp(1264001747)
    datetime.datetime(2010, 1, 20, 10, 35, 47)
    

    The value 1264001747 is the timestamp given in seconds from epoch. The returned datetime object is shown in the order (year, month, day, hour, minute, second)