Reputation: 289
I have bunch of datetime stamps in multiple timezone, similar to 2017-03-02T18:00:00+04:00 which are TZ aware.
The idea is to convert each of them to UTC TZ aware format like 2017-03-02T14:00:00+00:00
Is there a way to detect time zone from GMT offset and then pytz for the conversion?
Upvotes: 0
Views: 51
Reputation:
Yes, you can do that.You should use astimezone
method with the desired timezone as below:
import pytz
from dateutil import parser
dt = parser.parse('2017-03-02T18:00:00+04:00')
print(dt.astimezone(pytz.utc))
The result will be:
2017-03-02 14:00:00+00:00
Upvotes: 2