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
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
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.
You may save them into different vars and do somthing like:
a = @comment.created_at.strftime("%I:%M")
b = @comment.created_at.strftime("%P").downcase
c = @comment.created_at.strftime("%b %d")
e = a+b+" "+c #=> 10:32am Dec 19
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
This post or this should give you what you need. YOu basically define a custom Time format within in the initializers.
If you want to have it from the API, they show what the defaults are in the Time class