jjzjj

TimeWithZone

全部标签

ruby-on-rails - 如何将 ActiveSupport::TimeWithZone 实例格式化为指定格式

我有一个ActiveSupport::TimeWithZone实例,如2014-12-2205:54:34UTC,但我只想保留日期信息2014-12-22我试过Rail的to_formatted_s,但它对我不起作用。显示:2014-12-2205:54:34 最佳答案 您可以使用strftime:>date_time.strftime('%Y-%m-%d')在哪里,%Y-Yearwithcentury%m-Monthoftheyear(01..12)%d-Dayofthemonth(01-31)
12