Search code examples
javascriptjquerydst

Does DST affect the Date() object


I am building a small web application that has some time based aspects to it like displaying and hiding things based on what hour in the day it is. My friend told me that this will work until DST comes around and then I will have to change all of the hour checks I have in place. Is this true?


Solution

  • When creating a new Date() it will represent the user's current time regardless of circumstances. From MDN:

    When no parameters are provided, the newly-created Date object represents the current date and time, specified in the local time zone, as of the time of instantiation.

    I would strongly recommend not trying to handle DST yourself, because it becomes heinously complicated once you get into the weeds.