Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting input type date in vue.js

I use bootstrap-vue, which includes an input type of date.

When I write some number, the default format is yyyyyy-mm-dd.

I want to change that format to yyyy-mm-dd.

like image 389
USER Avatar asked Mar 14 '19 05:03

USER


People also ask

How do I change date format in Vue?

In the example below we are using vue so therefore we create a method called formatDate() and pass in the date that we want to format. We then set our options of how we want the date to be shown. This is an object where we can choose if we want the month to be numeric or long for example.

How do I change the date format in input?

To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.

How do I make a date picker in HTML?

The <input type="date"> defines a date picker. The resulting value includes the year, month, and day.

What is VUE template?

Vue uses an HTML-based template syntax that allows you to declaratively bind the rendered DOM to the underlying component instance's data. All Vue templates are syntactically valid HTML that can be parsed by spec-compliant browsers and HTML parsers.


1 Answers

use a formatter:

:formatter="format"

Declare how the value should be formatted within this function:

format(value, event) {
    return moment(value).format('YYYY-MM-DD')
}

As an example using the momentjs library.

like image 74
Ohgodwhy Avatar answered Sep 18 '22 04:09

Ohgodwhy