开发者

Ruby / Rails 3: How to create a Date object from a Time object?

Given a Time object, say 2011-03-12 21:58:11 +1100, I would like to get the appropriate Date object (Sat, 12 Mar 2011).

What is the easiest way to achieve thi开发者_C百科s ?

Rails 3 extensions are welcome.


There's a to_date method for time that can be useful

Time.now.to_date


Looking at the 'Time' object documentation, you can simply use the to_date method.

date = your_time.to_date
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜