Convert data with JavaScript?

3

How do I convert the date in this type 02 Ago 2017 to 02/08/2017 ?

I'm using vuejs-datepicker and when selecting it comes in that format, and in the documentation says to do so ...

customFormatter(date) {
      return moment(date).format('dd MMM yyyy');
    }

But using moment, I wanted without moment, how would I do?

    
asked by anonymous 04.08.2017 / 16:34

1 answer

5

You can create an instance of type Date in JavaScript and use the toLocaleDateString() .

Capture date in American format:

let data = new Date(Date.parse('Aug 4, 2017'));

To display date in local format:

console.log(data.toLocaleDateString()) //"04/08/2017"

To display in American format:

console.log(data.toLocaleDateString('en-US'))
    
04.08.2017 / 16:53