I want convert GMT time to EST time and get a timestamp. I tried the following but don't know how to set timezone.
time = "Tue, 12 Jun 2012 14:03:10 GMT"
timestamp2 = time.mktime(time.strptime(time, '%a, %d %b %Y %H:%M:%S GMT'))
I want convert GMT time to EST time and get a timestamp. I tried the following but don't know how to set timezone.
time = "Tue, 12 Jun 2012 14:03:10 GMT"
timestamp2 = time.mktime(time.strptime(time, '%a, %d %b %Y %H:%M:%S GMT'))
If it is your local timezone and the timezone rules are the same for the given time as they are now then you could use stdlib-only solution (except for some edge cases):
Otherwise you need data from a historical timezone database to get the correct utc offset.
pytz
module provides access to the tz database:Note: POSIX
timestamp
is the same around the world i.e., your local timezone doesn't matter if you want to find the timestamp (unless your timezone is of "right" kind). Here's how to convert a utc time to the timestamp.Using pytz
Time zones aren't built into standard Python - you need to use another library. pytz is a good choice.