开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜