开发者

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

开发者 https://www.devze.com 2023-02-16 04:43 出处:网络
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).

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

精彩评论

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