[TZInfo-users] Using TZ to convert to EST
phil.ross at gmail.com
Tue Nov 13 17:21:03 EST 2007
On 13/11/2007, johnsheahan at charter.net <johnsheahan at charter.net> wrote:
> Thanks Philip,
> I am getting the local time but can't seem to get the time to be displayed in EST.
> I'm sorry I don't understand.....How should I change my code to convert to EST?
I'm assuming that you are now seeing a time displayed that is correct
for EST, but the formatted string is indicating that it is UTC.
If you want to stop it saying UTC, then you will need to format the
time yourself. There are several options to do this:
1) Use the Ruby on Rails to_formatted_s function on the Time object
2) Use the strftime function of the returned Time object
(http://www.ruby-doc.org/core/classes/Time.html#M000297). If you use
%Z in the format string though, this will probably output UTC.
3) Use the TZInfo::Timezone.strftime function
This takes a time in UTC, converts it to local time and formats it
using the same options as the Time strftime function. However, %Z will
be translated to the correct abbreviation for the Timezone (i.e. EST
or EDT for New York).
http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby
More information about the TZInfo-users