Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
16
rated 0 times [  18] [ 2]  / answers: 1 / hits: 5221  / 5 Years ago, tue, december 10, 2019, 12:00:00

i've a vue apps containing datepicker by ant-design-vue that return



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


where i need the date format in YYYY-MM-DD



it's succeed when get straight from onChange event with this code.



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


but in my project, i'm using v-decorator where gets all data through the form.
this is my script where i've tried calling the date:



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


this is my datepicker structure:



<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>


and it's return the above moment. how can i get only YYYY-MM-DD format?


More From » date

 Answers
9

Have you tried this below? It




For initial Rendering
initialValue: moment(profile.birthday).format(YYYY-MM-DD)




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



For Submission:




this.form.validateFields((error, values) => {
let birthday = moment(values.birthday).format(YYYY-MM-DD);

console.log(birthday);
)}


Let me know if it works for you and should you need more clarification.


[#5384] Thursday, December 5, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
josuea

Total Points: 609
Total Questions: 121
Total Answers: 104

Location: South Georgia
Member since Fri, Nov 13, 2020
4 Years ago
josuea questions
Tue, Mar 2, 21, 00:00, 3 Years ago
Fri, Apr 17, 20, 00:00, 4 Years ago
Fri, Sep 27, 19, 00:00, 5 Years ago
Sat, Jun 8, 19, 00:00, 5 Years ago
;