Ivan Ivan - 1 year ago 89
jQuery Question

Receiving a not expected date after formating with Moment.js

I'm having problems formatting a date. I expect to receive the date "12/07/2016" instead of "13/07/2016". Why a day is added to my formatted date?

$("#donationDate").val("2016-07-12 00:00:00.0");

Best wishes,


Answer Source


You haven't pass anything in params to moment().Therefore by default it returns a moment object corresponding the current moment ( today we are the 13th of July ).

Then you are plugging a .format() that formats the moment object to DD-MM-YYYY. That's why it returns 13-07-2016.

You probably wanted to do something like moment(2016-07-12 00:00:00.0).format('DD-MM-YYYY') which returns 12-07-2016

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download