Transform DateTime into simple Date in Ruby on Rails

前端 未结 6 821
不思量自难忘°
不思量自难忘° 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:24

    DateTime#to_date does exist with ActiveSupport:

    $ irb
    >> DateTime.new.to_date
    NoMethodError: undefined method 'to_date' for #
        from (irb):1
    
    >> require 'active_support/core_ext'
    => true
    
    >> DateTime.new.to_date
    => Mon, 01 Jan -4712
    

提交回复
热议问题