Format date with javascript [duplicate]

0

I'm developing an application in which I get the postings of a page on facebook and I need to format the creation date of the post I get via json as follows:

2018-01-12T11:25:41+0000

What function should I use to format this date into the Brazilian standard? Ex: 01/12/2018.

    
asked by anonymous 12.01.2018 / 18:11

2 answers

2

You can pass the locale when you use the toLocaleDateString() function:

let data = new Date();
console.log(data.toLocaleDateString('pt-BR'));
    
12.01.2018 / 18:20
6

Instantiate string as a new Date and use the toLocaleDateString() function

var data = new Date('2018-01-12T11:25:41+0000');
console.log(data.toLocaleDateString('pt-BR'));
    
12.01.2018 / 18:20