From: Eric Hodel Date: 2012-08-30T09:47:13+09:00 Subject: Re: how do extract timezone from datetime object? On Aug 29, 2012, at 5:32 PM, Dan Quach wrote: > I'm working on an external interface where a partner website is giving > us date time as strings. > >>> dt = DateTime.parse( "Wed, 29 Aug 2012 17:26:44 -0700" ) > => Wed, 29 Aug 2012 17:26:44 -0700 >>> dt.strftime( "%z" ) > => "-0700" > > What I have to do is extract the UTC time zone. So in the prior example > I need an integer of -7. (UTC-7) in this scenario. > > Is there some easy way of doing this? What do you do for "Wed, 29 Aug 2012 17:26:44 +0630" (Myanmar and Cocos Islands) or other half-hour time zones? zone_offset = df.strftime("%z").to_i 10 "UTF%+i" % (zone_offset / 100)