How do I format datetime in rails?

前端 未结 4 1502
无人共我
无人共我 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-05 09:36

    For the format you have requested:

    <%= link_to timeslot.opening.strftime(%d/%m/%y: %H:%M:%S %Z), [@place, timeslot] %>
    

    More options available here:

    http://rorguide.blogspot.co.uk/2011/02/date-time-formats-in-ruby-on-rails.html

提交回复
热议问题