Currently we are working on an application which is trying to calculate the travel time of a route from a to b, using the 2.db.transport.rest API.
Unfortunatly we are receiving timestamps with a timezone offset from that API, such as +01:00
. What we need is a timezone offset without the :
, so +0100
.
The following example gives an error on Linux, using Python 3.6.7:
from datetime import datetime
datetimestring = "2019-01-19T15:13:00.000+01:00"
datetime.strptime(datetimestring, '%Y-%m-%dT%H:%M:%S.%f%z')
This example code produces this exception:
ValueError: time data '2019-01-19T15:13:00.000+01:00' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'
If we remove the :
from the input string it works, no exception is thrown.
The code also works when we run this on Windows, on Python 3.7.2.
Could it be due to the different Python versions? How can we parse or convert this without error?