首页 > 解决方案 > 如何更改 b-input 日期类型格式?

问题描述

我正在使用bootstrap-vue b-inputwith type='date',默认日期格式显示 dd/MM/yyyy。如何将其更改为 dd-MM-yyyy?

<b-form-group :invalid-feedback="errors.first('birth_date')"
                  :state="!errors.has('birth_date')"
                  class="col-sm-4"
                  label="Birth Date"
                  label-for="new-employer-owner-birth-date">
      <b-input :state="!errors.has('birth_date')"
               id="new-employer-owner-birth-date"
               name="birth_date"
               type="date"
               v-model="newOwner.birth_date"
               v-validate.disable="validation.birth_date">
      </b-input>
    </b-form-group>

我在属性:formatter="formatDate之后添加了“,'type'但它也不起作用。

标签: bootstrap-4vue-component

解决方案


newOwner.birth_date 的格式应为 YYYY-MM-DD

如果你使用 moment(),你可以像这样格式化你的日期

const unformattedDate = yourDate;

newOwner.birth_date = moment(unformattedDate).format("YYYY-MM-DD");

推荐阅读