Right now I have:
Time.strftime("%I:%M%p")
which gives me the hr:min AM/PM
format which I need. However it's coming back in UTC and I need it local time zone.
How do I change it to local time zone and keep that same format for time?
Also, remember that as of Rails 2.1, Timezones are supported.
in your config/environment.rb file:
config.time_zone = 'UTC'
You can find other values by running
rake time:zones:local
And Ryan Bates has a great railscast on it: http://railscasts.com/episodes/106-time-zones-in-rails-2-1
Generally that should work. You may have your time-zone set incorrectly, though:
Time.now.strftime("%I:%M%p") # => "12:48PM"
Time.now.utc.strftime("%I:%M%p") # => "04:48PM"
Time.now.utc.getlocal.strftime("%I:%M%p") # => "12:48PM"
Time.now.zone # => "EDT"
This can be affected by the TZ environment variable, your OS locale settings, or your Rails configuration in environment.rb.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With