Rails 3 default datetime format without UTC

datetime, ruby-on-rails, ruby-on-rails-3

Solution

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:

<%= l trip.truckleft, :format => :long %>

There are a few predefined date and time formats like `:long` available to you already for English, and you can add your own in `config/locales/en.yml` by following the YAML structure in those examples. If you're not getting heavily into the whole i18n/l10n thing just yet and looking at the `l` method all the time is confusing, you can also use:

<%= trip.truckleft.to_formatted_s(:long) %>

Problem

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!

Original source