我如何获取格式为(YYYY-MM-DD)的矩型日期选择器的值

问题描述 投票:0回答:1

我有一个由ant-design-vue包含datepicker的vue应用返回

Moment {…}
_d: Thu Oct 24 1996 00:00:00 GMT+0800 (Malaysia Time)
_f: "YYYY-MM-DD"
_i: "1996-10-15"
_isAMomentObject: (...)
_isUTC: (...)
_isValid: (...)
_locale: (...)
_pf: (...)
__ob__: Observer {value: Moment, dep: Dep, vmCount: 0}
get _d: ƒ reactiveGetter()
set _d: ƒ reactiveSetter(newVal)
get _f: ƒ reactiveGetter()
set _f: ƒ reactiveSetter(newVal)
get _i: ƒ reactiveGetter()
set _i: ƒ reactiveSetter(newVal)
get _isAMomentObject: ƒ reactiveGetter()
set _isAMomentObject: ƒ reactiveSetter(newVal)
get _isUTC: ƒ reactiveGetter()
set _isUTC: ƒ reactiveSetter(newVal)
get _isValid: ƒ reactiveGetter()
set _isValid: ƒ reactiveSetter(newVal)
get _locale: ƒ reactiveGetter()
set _locale: ƒ reactiveSetter(newVal)
get _pf: ƒ reactiveGetter()
set _pf: ƒ reactiveSetter(newVal)
__proto__: Object

我需要YYYY-MM-DD中的日期格式的地方>

使用此代码直接从onChange事件获得成功。

function(date = moment, dateString) {
      if (date) {
        console.log(dateString)
}

但是在我的项目中,我使用的是v-decorator,它通过表单获取所有数据。这是我尝试调用日期的脚本:

this.form.validateFields((error, values) => {
          console.log(values.birthday);
)}

这是我的日期选择器结构:

<a-form-item v-bind="formItemLayout" label="Date Of Birth">
    <a-date-picker
     v-decorator="[ 'birthday',
      {
       initialValue: moment(profile.birthday),
        rules: [{required: true, message: 'Date Of Birth is required.'}]
      },
     ]"
       @change="handleAge"
       format="DD/MM/YYYY"
      style="width:120px;"
      />
     </a-form-item>

返回上面的时刻。我如何只获取YYYY-MM-DD格式?

我有一个由ant-design-vue包含datepicker的vue应用程序,它们返回Moment {…} _d:1996年10月24日星期四00:00:00 GMT + 0800(马来西亚时间)_f:“ YYYY-MM-DD” _i :“ 1996-10-15” _isAMomentObject:(...)_isUTC:...

javascript date vue.js ant momentjs
1个回答
0
投票

https://momentjs.com/稍后,谢谢,这会将您的日期格式化为您可能会想到的文档格式:)不要忘了从“时刻”中导入时刻

© www.soinside.com 2019 - 2024. All rights reserved.