user1050619
user1050619

Reputation: 20856

Convert datetime string based on offset to datetime

I have a datetime string and need to convert it to datetime object based on the given offset.

>>> dt = iso8601.parse_date('2016-07-22 11:16:13+00:00')
>>> tzlocal = tz.tzoffset('local',-240)
>>> dt = dt.astimezone(tzlocal)
>>> dt
datetime.datetime(2016, 7, 22, 11, 12, 13, tzinfo=tzoffset('local', -240))

I have this datestring when converted its set to 11:12:13, I don't see its being changed to the offset given (which is -4 hours).

Upvotes: 0

Views: 53

Answers (1)

Almidas
Almidas

Reputation: 379

The offset is given in seconds. You indeed did get an offset, but -240 is 4 minutes. 11 hours 12 minutes 13 seconds from 11 hours 16 minutes 13 seconds. Change -240 to -4*60*60 to prevent confusion.

Upvotes: 2

Related Questions