3

My code

nouveautes.forEach(function(nouveaute) {
  console.log(nouveaute.createdAt.toLocaleString());
  nouveaute.createdAt = nouveaute.createdAt.toLocaleString();
  console.log(nouveaute.createdAt.getMonth());
  nouveaute.createdAt = nouveaute.createdAt.getMonth() + " " + nouveaute.createdAt.getYear();
  console.log(nouveaute.createdAt);
});

Output with 2 objects in array

2017-11-12 16:15:03
10
2017-11-12T15:15:03.000Z

2017-11-10 11:09:10
10
2017-11-10T10:09:10.000Z

I'd like to have :

In french :

// => Novembre 2017

Or if it's too difficult, in english :

// => November 2017
XavierB
  • 2,198
  • 1
  • 9
  • 12

2 Answers2

3

You can use Date.prototype.toLocaleDateString()

var date = new Date(Date.UTC(2017, 11, 20, 3, 0, 0));

var options = { year: "numeric", month: "long"};
console.log(date.toLocaleDateString("fr-FR", options));
// -> Novembre 2017
Thefirstalpha
  • 41
  • 1
  • 4
1

used moment.js library!

moment.lang('fr');
moment().format('MMMM YYYY');

https://momentjs.com/ https://www.youtube.com/watch?v=9JRvJ9aMLzc

Mr. Aniket
  • 83
  • 11