Q:

Handling of timezones in strptime in Python

I have two string like these:
"Sun 10 May 2015 13:54:36 -0700"
"Sun 10 May 2015 13:54:36 +0000"

(The last part is time zone -0700 means 7 hours less than GMT)
 My intention is turn it to a unix timestamp to find their absolute difference easily.

My Question is is there a built-in method for turning these formated texts to Unix timestamp? Or Is there a one that computes difference of two such strings directly??
Edit:
This Question differs from This one  since that problem doesn't include time zones and not any of answers to that question mentioned anything about time zone.

A:

This should work on Python 3 & above but not known to work on all platforms on Python 2.
date_str = "Sun 10 May 2015 13:54:36 -0700"
pattern =  '%a %d %B %Y %H:%M:%S %z'
dt = int(time.mktime(time.strptime(date_str ,pattern )))
print(dt)

For, Python 2.7+, (without %z)
import datetime
date_str = "Sun 10 May 2015 13:54:36 -0700"

dt_str = date_str[:-5].strip()
dt_zone = int(date_str[-5:])/100
pattern =  '%a %d %B %Y %H:%M:%S'

dtobj = datetime.datetime.strptime(dt_str ,pattern)
dt = dtobj + datetime.timedelta(hours=dt_zone)
print( dt.strftime('%s') )

