How do I format datetime in rails?

前端 未结 4 1505
无人共我
无人共我 2021-02-05 08:51

In my Rails view, I have the below code that displays a datetime.

<%= link_to timeslot.opening, [@place, timeslot] %> 

The result of this

4条回答
  •  日久生厌
    2021-02-05 09:37

    Use ruby's strftime() on dates/datetimes:

    <%= link_to timeslot.opening.strftime("%Y %m %d"), [@place, timeslot] %>
    

    Have a look at the documentation to find out how the formatting works.

提交回复
热议问题