DEV Community

Discussion on: Countdown Timer using HTML, CSS, and Javascript

lukeshiru profile image
Luke Shiru • Edited on

You're right, wth?! JavaScript being JavaScript I guess ... if you do new Date() it gives you the current date, but if you do new Date(undefined) which should be the same, it returns an Invalid Date .... gosh ... I'll update the original code! ... thanks for debugging it!

Thread Thread
supportic profile image
Supportic • Edited on

No worries new Date(undefined) always throws 'Invalid Date' in the console and new Date(null) returns the starting point.
Thanks for the neat snippet though.
Could you also explain why we subtract 621672192e5 ?

Thread Thread
lukeshiru profile image
Luke Shiru

Sure, that 621672192e5 value is 0000-01-01T00:00:00.000Z, so the "first day" of the Gregorian calendar, if we have two dates and we subtract that, we get the "difference" between those two dates ... this is still the "cheap/non-exact" version, if you want something more useful, you might have to update it so it does the actual values for each property. I might do that later so the example is more useful for other folks.