Bob Sumo
Bob Sumo

Reputation: 207

Formatting Date Output Hash

The output from my hash is giving me the following date time:

16 May 11 13:12:14 +0000

How do I go about formatting this into something sensible?

Thanks

Upvotes: 0

Views: 656

Answers (1)

robertwbradford
robertwbradford

Reputation: 6605

I'll assume you are wanting this output in a view... First, you can create some formats:

# /config/locales/en.yml:
en:
  date:
    formats:
      full: "%b %d, %Y"

  time:
    formats:
      full: "%B %d, %Y at %I:%M%p"

Then you can display a datetime in a view using the l method with specified format:

<%= l @something.updated_at, :format => :full %>

This would display something like the following:

May 16, 2011 at 01:12pm

More on the i18n formats

List of available directives

Upvotes: 1

Related Questions