Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 706
AnApprentice Avatar asked Dec 19 '10 18:12

AnApprentice


People also ask

How do I change the date format in Ruby?

You need to convert your string into Date object. For that, use Date#strptime . You can use Date#strftime to convert the Date object into preferred format.


2 Answers

Try to use %P instead using %p

like image 50
DANDYYeah Avatar answered Oct 07 '22 01:10

DANDYYeah


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.

like image 23
noodl Avatar answered Oct 07 '22 01:10

noodl