I’m creating a new Rails 3 app, and in it I use DateTime for a couple of fields, however every datetime field standard has UTC behind it (in a view), like:
2010-10-10 16:19:00 UTC
How do I get rid of the UTC part?
UPDATE: here’s what I have so far:
<%= trip.truckleft.strftime("%Y-%m-%d %H:%M") %>
So all I have to do now is put that in a helper, but isn’t there a better more universal way?
I looked at some other posts, that suggested creating a time_formats.rb in initializers, however I didn’t have any success doing that.
Thanks for your help, much appreciated!
Another — perhaps now preferred — way is to use Rails’ internationalization and localization support. There’s a lot to learn in that guide, so the tl;dr version is this:
There are a few predefined date and time formats like
:longavailable to you already for English, and you can add your own inconfig/locales/en.ymlby following the YAML structure in those examples. If you’re not getting heavily into the whole i18n/l10n thing just yet and looking at thelmethod all the time is confusing, you can also use: