I previously asked a question on stack overflow about how to format my date in a readable manner. This was the gist of it was this.
How do I take
2010-06-14 19:01:00 UTC
and turn it into
June 14th, 2010
The answer that I used was calling post.date and simply adding the below to post.rb
@date = Time.now
@date.strftime("%B %d, %Y")
It does show the date in words but I don't want to show the current date. I want the post.created_at date.
How can I modify the above (or what do I need to add elsewhere) to get this to work?
post.created_at.strftime("%B %d, %Y")
A good resource for strftime is http://strfti.me
You can define your own formatters for reuse as initializers.
# config/initializers/time_formats.rb
Time::DATE_FORMATS[:nice] = "%B %d, %Y"
Then use
User.created_at.to_formatted_s(:nice)
Reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With