Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
utc_to_local returning UTC identifier #26
I'm using utc_to_local to convert a time in UTC to "America/Vancouver"
The time is correct, however it still displays +0 UTC at the end. How do I get this to display the correct UTC offset?
Running rails 2.3.18 and Ruby 1.8.7
If you are just interested in finding the UTC offset at a given time, you can use the
>> start_time = Time.utc(2014,9,25,18,30) => Thu Sep 25 18:30:00 UTC 2014 >> tz = TZInfo::Timezone.get('America/Vancouver') => #<TZInfo::DataTimezone: America/Vancouver> >> tz.period_for_utc(start_time).utc_total_offset => -25200
Since you are using Rails, you could also use the
>> start_time = Time.utc(2014,9,25,18,30) => Thu Sep 25 18:30:00 UTC 2014 >> start_time.in_time_zone('America/Vancouver') => Thu, 25 Sep 2014 11:30:00 PDT -07:00
Note that this returns an instance of
ActiveSupport uses TZInfo internally for handling time zones.