How do I find difference between times in different timezones in Python?

Posted by JasonA on Stack Overflow See other posts from Stack Overflow or by JasonA
Published on 2010-05-13T15:43:57Z Indexed on 2010/05/13 15:44 UTC
Read the original article Hit count: 175

Filed under:

Hi All,

I am trying to calculate difference(in seconds) between two date/times formatted as following:

2010-05-11 17:07:33 UTC

2010-05-11 17:07:33 EDT

time1 = '2010-05-11 17:07:33 UTC'
time2 = '2010-05-11 17:07:33 EDT'
delta = time.mktime(time.strptime(time1,"%Y-%m-%d %H:%M:%S %Z"))-\
        time.mktime(time.strptime(time2, "%Y-%m-%d %H:%M:%S %Z"))

The problem I got is EDT is not recognized, the specific error is

"ValueError: time data '2010-05-11 17:07:33 EDT' does not match format '%Y-%m-%d %H:%M:%S %Z'"

Thanks,

© Stack Overflow or respective owner

Related posts about python