@object.updated_at.localtime displays "2015-04-20 14:39:27 -0700". I don't want to display the -0700, is there a method that will strip out the timezone for display purposes?
Asked
Active
Viewed 9,175 times
3
-
possible duplicate of [Ignoring timezones altogether in Rails and PostgreSQL](http://stackoverflow.com/questions/9571392/ignoring-timezones-altogether-in-rails-and-postgresql) – Apr 23 '15 at 03:35
-
that's a great question and answer, but the scope is *much* larger than my question here... I really just needed help on the syntax for formatting .localtime. the answer I got was perfect. – Tim Koelkebeck May 08 '15 at 22:21
3 Answers
6
If you plan to use that format across your app, you might as well create a new time format:
# config/initializers/time_formats.rb
Time::DATE_FORMATS[:no_timezone] = "%Y-%m-%d %H:%M:%S"
Then just use it like this:
Time.now.to_s(:no_timezone)

Ian Vaughan
- 20,211
- 13
- 59
- 79

mrstif
- 2,736
- 2
- 27
- 28
3
You should use I18n.l
and define a format in. your language.yml
I18n.l @object.updated_at, format: :my_format
en.yml
en:
time:
formats:
myformat: "%Y-%m-%d %H:%M"

joseramonc
- 1,811
- 2
- 21
- 40