Transform DateTime into simple Date in Ruby on Rails

前端 未结 6 937
不思量自难忘°
不思量自难忘° 2021-01-30 08:09

I have a datetime column in db that I want to transform into a simple date when I show it to users.

How can I do that?

def shown_date
  # to_date does not exi         


        
6条回答
  •  误落风尘
    2021-01-30 08:15

    In Ruby 1.9.2 and above they added a .to_date function to DateTime:

    http://ruby-doc.org/stdlib-1.9.2/libdoc/date/rdoc/DateTime.html#method-i-to_date

    This instance method doesn't appear to be present in earlier versions like 1.8.7.

提交回复
热议问题