I am working with some dates in JavaScript that follow the format YYYY-MM-DD HH:MM:SS
. When I go to convert this to a date object using const date = new Date(inputDate)
, I expect to receive a Date object that is in UTC time, however, what I am getting is a date that is in my local timezone.
I have tried following the steps described here to convert to UTC, but I haven't had any success. A workaround I found was to change my input date to include the desired timezone – that is YYYY-MM-DD HH:MM:SS UTC
, but this feels like a nasty workaround that does not scale very well.
I also cannot convert the newly created date to UTC after defining it, as this just gives the UTC representation rather than a date using the appropriate timezone
How can I go about having the Date be created in UTC so that any operations done with Date.now()
and the created date don't have a timezone difference?