2

I have a datetime object t which is in UTC time but attached with Alaska timezone offset(-08:00):

t
-> datetime.datetime(2019, 3, 23, 15, 49, 34, tzinfo=tzfile('/usr/share/zoneinfo/America/Anchorage'))

I try to convert t to a datetime tuple in Alaska localtime. I do like this but I still get the UTC time.

time.strptime(str(t),"%Y-%m-%d %H:%M:%S%z")
-> time.struct_time(tm_year=2019, tm_mon=3, tm_mday=23, tm_hour=15, tm_min=49, tm_sec=34,\
 tm_wday=5, tm_yday=82, tm_isdst=-1)

So the time.strptime() will not process the offset, even I input it in the format(%z means the offset)?

What should I do to get:

-> time.struct_time(tm_year=2019, tm_mon=3, tm_mday=23, tm_hour=7, tm_min=49, tm_sec=34,\
 tm_wday=5, tm_yday=82, tm_isdst=-1)

(tm_hour I want is 7 = 15 - 8)

Thanks so much!

0 Answers0