I can already pull the data from api with v-model, but this is how i see the date 2022-04-23T13:39:00+03:00
but I want it to come this way 2022-04-23 13:39
Here is my html code
<Field
class="form-control"
type="text"
v-model="date"
name="date"
:placeholder="$t('form.label.date')"
/>
Here is my ts code
data() {
date:"",
}
setup() {
const dateFormat = (date) => {
return moment(date).format("YYYY-MM-DD HH:mm");
};
}
If you are only rendering the value and don't need to setup two-way binding or reactivity, you can just resolve the formatting before passing the formatted value to the template.
You can also pass a formatter function to the template that will render the formatting to you liking.
While there are several options for formatting dates. To avoid adding additional dependencies, I'm using
Intl.DateTimeFormat
in the example. It's a little hacky, since the format is not in any international standard (or it is, and just don't know which one). I've also used date-fns with success, but as mentioned in the comments, you should not be using moment. Moment is built in a way that doesn't allow tree-shaking unused parts during packaging, so leads to bloat.