From: Nathan Beyer Date: 2012-08-30T09:52:07+09:00 Subject: Re: how do extract timezone from datetime object? I was going to suggest converting to a Time via DateTime#to_time, so you could use Time#utc_offset / 3600, but 'to_time' doesn't preserve the timezone. There is a Datetime#offset that you can use, but i returns a Rational that's a fraction, so you can do something like this - 1.9.3p194 :018 > dt = DateTime.parse( "Wed, 29 Aug 2012 17:26:44 -0700" ) => # 1.9.3p194 :019 > dt.offset.numerator => -7 That seems a bit wonky though. On Wed, Aug 29, 2012 at 7: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? > > thanks! > > -- > Posted via http://www.ruby-forum.com/. >