I was trying to convert ISO 8601 YYYYMMDDThhmmss.SSS + 900
to Unixtime.
Since % z
is not supported in strptime
in python2.7, date conversion using timezone is troublesome. When I use % z
, I get angry as follows.
ValueError: 'z' is a bad directive in format '%Y%m%dT%H%M%S.%f%z'
I tried to convert datetime <-> string with tzinfo using strftime () and strptime () However, I noticed that the conversion from JST to JST didn't have to worry about zone specifiers.
Time zone If you can't use it Erase
>>> from datetime import datetime
>>> import time
>>> int(time.mktime(datetime.strptime('20160323T204100.001+0900'.replace('+0900', ''), '%Y%m%dT%H%M%S.%f').timetuple()))
1458733260
It's a bit brute force, but it's simple.