I am getting a date of birth in yyyy-mm-dd format. I want it in dd-mm-yyyy format. How can this be done in Ruby?
Here is my code:
index.html:
<div class="row">
<div class="col-md-6 dob">
<%#= f.input :date_of_birth %>
<%= f.date_select :date_of_birth,
{:start_year => Time.now.year,
:end_year => 1900,
:use_short_month => true,
:order => [:month, :day, :year],
:prompt => {:day => 'Day',:month => 'Month', :year => 'Year'}}
</div>
show.html:
<div class="col-md-10 primary-info-label">
<label><%= @user.date_of_birth %></label>
</div>
To modify the format of the date of birth in your view, you can use strftime
:
<div class="col-md-10 primary-info-label">
<label><%= @user.date_of_birth.strftime("%d-%m-%Y") %></label>
</div>
The above should format the date_of_birth to be in mm-dd-yyyy format. More info on strftime
here .
Hope it helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.