Getting the timezone (the GMT offset) from DateTime

Hi everyone!

How do you get the timezone (in the format: +0800) from a time object?

Please see http://pastie.caboo.se/70979

Thank you,

Ramon T.

%z will do the job, but…
are you sure you are doing timezone related stuff in a right way?
usually it is better to store your times in UTC timezone, converting
back and forth to user’s, user location’s or whatever entity’s you’ll
find appropriate local timezone.

On Jun 16, 9:38 am, “Ramon Miguel M. Tayag” [email protected]

%z gives me “Malay Standard Pacific Time” (or something like that). I
figured it’d be much easier to make a timezone drop down (just like
all the other sites out there).

“are you sure you are doing timezone related stuff in a right way?”
– Not at all :o

Thanks :slight_smile:

On 6/16/07, liquidautumn [email protected] wrote:


Ramon T.

Try Time.new.localtime.strftime “%z” ?

Thanks, kates, will do :slight_smile:

On 6/23/07, kates [email protected] wrote:

Try Time.new.localtime.strftime “%z” ?


Ramon T.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs