vue3-datepicker
vue3-datepicker copied to clipboard
Convert Fri Sep 17 2021 10:12:00 GMT+0530 (India Standard Time) to yyyy-mm-dd
I am using vuejs 3 and vue3-datepicker.
<datepicker
v-model="to_date"
inputFormat="yyyy-MM-dd"
/>
my data method is :
data(){
to_date: new Date(),
}
When I am selecting a date and printing {{this.to_date}}, it is printing in Fri Sep 17 2021 09:39:49 GMT+0530 (India Standard Time).
I want it in yyyy-MM-dd format.
How can I achieve this?
Hi, this isn't really anything to do with the date picker. Input format is to do with how the user inputs the date rather than how it's stored. It's just stored as a normal javascript Date object. The way to do this would be to do something like to_date.getFullYear() + "-" + (to_date.getMonth() + 1) + "-" + to_date.getDate()
khems provided a correct answer. To add, since this library depends on date-fns, you can use it's functionality https://date-fns.org/v2.30.0/docs/format