Rails - get date from date & time stamp
In my Rails database, I have a timestamp that looks like this 2开发者_如何学JAVA010-12-22 18:21:46 UTC
. I need a way to just get the date 2010-12-22
from it without re-doing the database.
Try time.to_date
to extract date component from your timestamp.
To get the String
you're looking for
your_date.strftime("%Y-%m-%d")
Not sure what you mean about modifying the database?
To get the String you're looking for
your_date.strftime("%F")
below link u can get more type of date. http://ruby-doc.org/core-2.2.0/Time.html#method-i-strftime
精彩评论