Can someone please help me understand why this set of functions always calculates the date a day behind?
const parseISOString = (isoStr) => {
return new Date(Date.parse(isoStr))
}
const formatDt = () => {
const dtInISOFmt = "2019-12-01T05:00:00.000+00:00"
const dateStrParts = parseISOString(dtInISOFmt).toDateString().split(" ")
const month = dateStrParts[1]
const day = dateStrParts[2]
const year = dateStrParts[3]
return [day, month, year].join(" ")
}
console.log(`formatDt(): ${formatDt()}`)
Here's a quick plunkr with the same: https://plnkr.co/edit/X3EkEZM6uNDPA36w
Quick background: Was trying to do some basic date formatting/parsing without importing any major date formatting JS libraries (e.g. moment) into my application, to reduce it's size / footprint.
Any and all help much appreciated.
Thanks in advance!