Monthly archive

Javascript Date is One Day Off

ben himself's picture

In JavaScript, dates are based on the UTC time, the starting timezone which all others are based on. You may have a date in JavaScript that should be one particular date but for some reason changes itself to the previous day. The way to fix it is to add the timezone offset to the date. Here's an example:

jsfiddle example: https://jsfiddle.net/xhzce36p/1/