Blankman
Blankman

Reputation: 266940

In Rails, how to display date like NOV 22, '09?

In Rails, how to display date like NOV 22, '09?

And time like: 5:10 PM

Upvotes: 1

Views: 239

Answers (2)

Chirantan
Chirantan

Reputation: 15634

Date.today.strftime "%b %d, '%y"
Time.now.strftime "%I:%M%p"

Upvotes: 2

Sam Ritchie
Sam Ritchie

Reputation: 11038

Check out the section 3.2, "Adding Date and Time Formats", in th Internationalization Rails Guide. You'll declare the format in a locales file using (I believe):

# config/locales/custom.yml
custom:
  time:
    formats:
      short: "%b %d, '%y"

and call it in your view with:

<p><%= l Time.now, :format => :short %></p>

Upvotes: 4

Related Questions