I have found many examples on the internet of converting from seconds or milliseconds to a JavaScript Date, but only a few for converting from days to a Date object. When I tried these examples in my own code (with my own values), I was unable to replicate their results.
My API returns an integer value representing days since UNIX epoch. I need to find a way to convert this to a JavaScript date object, so that I can display it in a human readable format.
For example:
new Date(18521 * 86400 * 1000)
// multiply by 86400 (seconds in a day), then by 1000 to convert to milliseconds.
At the time of writing, the date is 9/17/2020 MMDDYYYY, and 18522 days have passed since UNIX epoch. However, when I try to retrieve yesterday's UNIX date 18521 using the date constructor with some math (mentioned above), I get the incorrect date: Sep 15 2020. I would expect to get (Sep 16 2020) since I have only subtracted one day, but for some reason that is not the case.
Is there anything I am doing incorrectly here? What should I change to make my code work?