I have a Vue application with a datepicker from Ant Design Vue that is returning the following moment object:
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
I need to extract the date in YYYY-MM-DD
format.
When I retrieve the date directly from the onChange event using this code snippet, it works:
function(date = moment, dateString) {
if (date) {
console.log(dateString)
}
However, in my project, I'm using v-decorator to obtain all data from the form. Here's the script where I tried to get the date:
this.form.validateFields((error, values) => {
console.log(values.birthday);
)}
This is the structure of my datepicker component:
<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>
The above setup returns the moment object mentioned earlier. How can I receive only the date in YYYY-MM-DD format?