Based on this related question and answer I asked, it has become obvious that datetime.fromtimestamp(os.path.getctime())
in Python 3.4 doesn't return a timezone-aware datetime object, However, based on some investigation, I've also discovered that OS X 10.9 on an HFS+ filesystem (for example) does seem to maintain the timezones along with ctimes (unless gls is inferring the timezone from my local timezone and daylight-savings time):
$ gls -l --full-time -c
-rw------- 1 myuser staff 538 2015-01-04 17:12:57.000000000 +0100 fileone
-rwxr-xr-x 17 myuser staff 578 2015-05-20 06:41:07.000000000 +0200 filetwo
(I am using the GNU version of ls)
How can I get the timezone from the ctime and insert/combine it into a datetime object?
(I'd also like the same answer for the mtime, I assume it will be similar).
Both ctime and mtime are available as "seconds since epoch" (values returned by
time.time()
).To get the local timezone, you could use
tzlocal
module:You might see the timezone info because
ls
converts the timestamps into corresponding broken-down time with timezone offset using the local timezone.