I'm having trouble converting a UTC Time
or TimeWithZone
to local time in Rails 3.
Say moment
is some Time
variable in UTC (e.g. moment = Time.now.utc
). How do I convert moment
to my time zone, taking care of DST (i.e. using EST/EDT)?
More precisely, I'd like to printout "Monday March 14, 9 AM" if the time correspond to this morning 9 AM EDT and "Monday March 7, 9 AM" if the time was 9 AM EST last monday.
Hopefully there's another way?
Edit: I first thought that "EDT" should be a recognized timezone, but "EDT" is not an actual timezone, more like the state of a timezone. For instance it would not make any sense to ask for Time.utc(2011,1,1).in_time_zone("EDT")
. It is a bit confusing, as "EST" is an actual timezone, used in a few places that do not use Daylight savings time and are (UTC-5) yearlong.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…