Time zone mapping from TimeZone to TZInfo::Timezone

Hi. Using this:

<%= time_zone_select("account", "time_zone" %>

I get a list of time zones options, like eg.:

<option value="Athens">(GMT+02:00) Athens</option>

But as I’m using TZInfo::Timezone, I need to map ‘Athens’ to

I can see that the mapping I’m looking for is present in the
tzinfo_timezone plugin, but I cannot see how to access it.




PS: I’m aware that I could use

<%=time_zone_select(“account”, “time_zone”,
TZInfo::Timezone.all.sort, :model => TZInfo::Timezone) %>

But the resulting select values look horrible, so I’d like to stick
with the Rails presentation format.

Hi Morten,

<%=time_zone_select(“account”, “time_zone”,
TZInfo::Timezone.all.sort, :model => TZInfo::Timezone) %>

Actually the code you mentioned above will give a result in the format
you are looking for.
i.e ‘Europe/Athens’

$tcode = @params[:account][:time_zone]
tz = TZInfo::Timezone.get($tcode)
tz = tz.local_to_utc(Time::now()).to_s

So, ‘tz’ will provide you the converted time.

Hope it helps you and others.


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