[TZInfo-users] Using TZ to convert to EST
phil.ross at gmail.com
Tue Nov 13 09:22:21 EST 2007
On 13/11/2007, John Sheahan <johnsheahan at charter.net> wrote:
> Thanks alot for pointing me in the right direction, Philip.
> Your explaination caused me to look hard at my Timezone.get statement and
> found that I was missing the _ between New and York.
> Once I fixed this, I am now getting time on my view, however, it is still in
> Here's my code that is giving me UTC:
> tz = TZInfo::Timezone.get('America/New_York')
> @local = tz.utc_to_local(tz.now)
> My service provider that my server is in is giving me Mountain Time, now
> that I have been able to change this to UTC, How can I change this to
> convert the UTC time to EST?
tz.now will give you the current local time in the timezone -
internally it runs tz.utc_to_local(Time.now.utc). You don't need the
extra call to utc_to_local.
Note that the local time returned will be described as UTC because
Ruby doesn't support arbitrary local timezones. The value of the time
will be the correct local time though.
http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby
More information about the TZInfo-users