Take the 2-minute tour ×

In my file I have columns of date in the ISO 8061 format with timezone information, here is the sample input


so the format is YYYY-MM-DDTHH:MM:SS[f]-AB:CD

I want to know how I can format the given data to format required by RFC 2445 iCalendar specification [DTSTART], which are example :

19970714T133000                    ;Local time
19970714T173000Z                   ;UTC time
TZID=US-Eastern:19970714T133000    ;Local time and time

I currently have following code for just parsing

>>> import dateutil.parser
>>> import dateutil
>>> import datetime
>>> dateutil.parser.parse('2009-01-29T07:00:00-05:00')
datetime.datetime(2009, 1, 29, 7, 0, tzinfo=tzoffset(None, -18000))

I want to know how to identify time zone ['-04:00','-05:00'] and how to convert them into UTC.

Thank you.

share|improve this question
I am a little confused.dateutil has already parsed timezone info for you. tzinfo=tzoffset(None, -18000). an hour has 3600s. -5:00 is -18000s –  Leonardo.Z Oct 30 '13 at 15:38
@Leonardo.Z so if I just subtract 5 hours from the original datetime, I would get UTC datetime ? –  Jenn Cole Oct 30 '13 at 15:45
No, you should not do the subtract manually. dt = dateutil.parser.parse('2009-01-29T07:00:00-05:00'), datatime object has a method to do the timezone conversion: dt.astimezone(pytz.utc) –  Leonardo.Z Oct 30 '13 at 15:55
@Leonardo.Z Thanks Leo :) Hope you have a relaxing day :) –  Jenn Cole Oct 30 '13 at 16:07
Leonardo is right. Besides, you would add 5 hours to get back to UTC. The offset means that the time is 5 hours behind UTC. Also recognize that just because you have -5 or -4 doesn't mean you can know that this is US Eastern Time. –  Matt Johnson Oct 30 '13 at 16:11
show 4 more comments


Your Answer



Browse other questions tagged or ask your own question.