You don't need datetime at all. Apple has kept its time since the beginning of its time, which was 2001-01-01. Super annoying but easy to overcome. Just add the difference between 1970-01-01 and 2001-01-01 in seconds before the variable and use the time to format it in one line of code:
import time mac_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data[0]/1000000000 + 978307200)) print mac_date
In this example, data [0] is the date I received from the sqlite query against chat.db, and this is the first field in the tuple. 978307200 is the difference between the unix era and the mac timestamp in seconds, and that will never change. When you add these two together and convert the unix era, you get a date that is accessible to humans.
* Starting with High Sierra, the chat.db file now uses nanoseconds. This requires that the date value be divided by 1,000,000,000.
source share