简体   繁体   中英

Rails form date_field is showing mm/dd/yyyy

Before I input anything into the rails form. The date_field is showing mm/dd/yyyy .

Is their a way for it to show dd/mm/yyyy .

Placeholder doesn't work.

I have looked around for an answer but none of the answers worked.

Thank you.

Here is the form data.

.flex.flex-column.w50p.mx-auto
  = form_for :agreegated_answer, url: survey_aggregated_answers_path(@survey), method: :post  do |f|
    = f.label :procedures_that_have_tags
    = f.collection_select(:tag_ids, @survey.tags, :name, :name, { selected: [] },
      multiple: true, class: 'js-input-tags border-light', placeholder: 'Select tags')
    = f.label :answered_from
    = f.date_field :start_from
    = f.label :answered_to
    = f.date_field :ends_from
    = f.submit 'Generate results'

在此处输入图片说明

使用ruby的strftime函数:

= f.date_field :start_from, value: @survey.start_from.strftime("%d/%m/%Y")

尝试这个:

<%= f.date_field :ends_from, as: :date, value: f.object.try(:strftime,"%d/%m/%Y") %>

The problem is my computer.

When im on someone elses computer it's dd/mm/yyyy when im on mine its mm/dd/yyy because my computer is American.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM