Alex Rivera | Logout

strftime formatting with Ruby/Rails -- Lowercase am/pm

Asked 2010-12-19T18:36:36.377
12

I have the following:

@comment.created_at.strftime("%I:%M %p %b %d")

Which outputs: 10:32 AM Dec 19

I'd like to output a lowercase am, like: 10:32am Dec 19

Any ideas on how to do that with ruby/rails?

thanks

Edit
Report

2 Answers

2

Use %P instead of %p. That'll work with ruby 1.9 but for 1.8 you'll need to use .sub(' AM ', ' am ').sub(' PM ', ' pm ') or similar.

answered 2010-12-19T18:52:27.207
1

it seems that in ruby 1.9 you can use %P instead of %p and don't forget to remove a space

@comment.created_at.strftime("%I:%M%P %b %d") =>10:32am Dec 19

answered 2013-02-11T09:39:48.827

Your Answer