0

I need to getFullYear on a JavaScript Date, however newing up a Date() creates it at UTC, and in the cases of January 1, it becomes LAST YEAR. (at my timezone, EST)

so:

startDateYear = new Date('2019-01-01').getFullYear()

returns 2018

I know .getISODate() does get the true date in my timezone, but I need to come up with a way to chain .getISODate() with .getFullYear() to get the true year.

DShultz
  • 4,381
  • 3
  • 30
  • 46
  • 1
    check it out this here https://stackoverflow.com/questions/2488313/javascripts-getdate-returns-wrong-date – pbachman Sep 21 '20 at 19:25
  • Thanks, there were some good ideas in multiple answers. – DShultz Sep 21 '20 at 20:40
  • YYYY-MM-DD is parsed as UTC, so use [*getUTCFullYear*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getUTCFullYear) or keep it simple: `'2019-01-01'.substring(0,4)` or `'2019-01-01'.split('-')[0]`. :-) – RobG Sep 21 '20 at 23:36

0 Answers0