I'm getting a date from MySQL and trying to parse it with moment
let date = moment('2017-02-27T00:00:00.000Z').format('YYYY-MM-DD')
console.log(date) //2017-02-26
Why am i losing a day; And what is the correct way to parse it?
This is happening because of Time Zone.
You can change it using .tz()
to use specific timezone or use .utc()
let date = moment('2017-02-27T00:00:00.000Z').utc().format('YYYY-MM-DD')
console.log(date) //2017-02-27
http://momentjs.com/timezone/docs/#/using-timezones/parsing-in-zone/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With