1

I have a date:

EventDate: "2018-10-10T00:00:00Z"

I run it through moment:

let date = moment(event.EventDate).format("MM/DD/YYYY");

And I get the previous day:

date:  10/09/2018

What is happening?

EDIT:

This is not a duplicate; there is a specific answer on moment that fixes the time zone issue.

Holden1515
  • 659
  • 2
  • 7
  • 20
  • 3
    Your date is the previous day in your time zone. – Heretic Monkey Oct 30 '18 at 17:59
  • Possible duplicate of [Why does Date.parse give incorrect results?](https://stackoverflow.com/questions/2587345/why-does-date-parse-give-incorrect-results) While this talks about the native Date object, that's what moment uses anyway. – Heretic Monkey Oct 30 '18 at 18:01
  • @HereticMonkey Yes, it is the same issue with time zones as your link. The answer is at 2 votes and near the bottom of the page. This one I feel gives a more succinct. – Holden1515 Oct 30 '18 at 19:26

1 Answers1

5

Use utc() to respect universal time, as your time format is already in utc.

var EventDate= "2018-10-10T00:00:00Z"
let date = moment(EventDate).utc().format("MM/DD/YYYY");

console.log(date)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://momentjs.com/downloads/moment.min.js"></script>
Amit Bhoyar
  • 1,007
  • 5
  • 20