Summary: "negative" timestamps on Mac work fine, but on Windows I can't convert them into something usable.
Details: I can have a file on Windows whose modification time is, say 1904:
$ ls -l peter.txt
-rw-r--r-- 1 sync Administ 1 Jan 1 1904 peter.txt
In python:
>>> import os
>>> ss = os.stat('peter.txt')
>>> ss.st_mtime
-2082816000.0
Great. But I can't figure out how to turn that negative timestamp into a date/time string. On Mac this code works fine.
>>> datetime.fromtimestamp(-2082816000)
datetime.datetime(1904, 1, 1, 0, 0)
And from here I can do whatever I want in terms of formatting.
But on Windows it fails:
>>> datetime.fromtimestamp(-2082816000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: timestamp out of range for platform localtime()/gmtime() function
And trying anything else I can think of fails:
>>> time.gmtime(-2082816000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: (22, 'Invalid argument')
the wonderful python-dateutil package doesn't seem to have this facility. I've looked though time, calendar, and datetime module. Any help?
>>> datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=-2082816000)
datetime.datetime(1904, 1, 1, 8, 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With