user3143105
user3143105

Reputation: 129

moment.format returning 3 days off

I have the following code in my Angular app:

ctrl.getDate = function() {
  console.log(ctrl.day.date); => 2017-12-06T05:00:00.000Z
  return moment(ctrl.day.date).format('MMMM do YYYY'); => December 3rd 
    2017
  };

What is going on here? The date passed is clearly 2017-12-06 but for some reason the '.format' method is changing it to a day 3 days earlier.

Upvotes: 2

Views: 58

Answers (2)

Mael
Mael

Reputation: 19

As Aleksey said capitalisation matters, with "do" you take the day of week and with "Do" you'll have the day of month. https://momentjs.com/docs/#/displaying/format/

Upvotes: 1

Aleksey Solovey
Aleksey Solovey

Reputation: 4191

Capitalisation matters:

return moment(ctrl.day.date).format('MMMM Do YYYY');

Changing do to Do

Upvotes: 1

Related Questions