I'm fairly new to Ruby on Rails. I created a blog using SQLite3, because I am unable to install MySQL, and would like to display the date of creation next to the title.
The date of creation is created using a timestamp. As I am new to RoR I created the blog using generate scaffold
so I'm not 100% sure how that all works.
At the moment, when I display the created_at
field, I'm given an ugly format:
2011-12-05 14:11:10 UTC
Is there a way to change this so that it display DD-MM-YYYY HH:MM
, or preferably to say "posted 30 days ago
". I realize the latter would be a lot more tricky.
I think you're looking for strftime
- ruby documentation here.
Example:
irb(main):001:0> a = Time.now
irb(main):002:0> a.strftime("%d-%m-%Y %H:%M")
=> "05-12-2011 15:08"
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