Skip to content

Instantly share code, notes, and snippets.

@yangwao
Created July 11, 2017 12:50
Show Gist options
  • Save yangwao/5223042dfe17c2267ff433dc515c2d93 to your computer and use it in GitHub Desktop.
Save yangwao/5223042dfe17c2267ff433dc515c2d93 to your computer and use it in GitHub Desktop.
Date mystery with timezones
Local
⫸ node -v
v0.12.18
> date = new Date(2017, 06, 01)
Sat Jul 01 2017 00:00:00 GMT+0200 (CEST)
> Math.floor(date/(86400*1000)) + 1
17348
> date = new Date(Date.UTC(2017, 06, 01))
Sat Jul 01 2017 02:00:00 GMT+0200 (CEST)
> Math.floor(date/(86400*1000)) + 1
17349
Server
node -v
v0.12.18
> date = new Date(2017, 06, 01)
Sat Jul 01 2017 00:00:00 GMT+0000 (UTC)
> Math.floor(date/(86400*1000)) + 1
17349
> date = new Date(Date.UTC(2017, 06, 01))
Sat Jul 01 2017 00:00:00 GMT+0000 (UTC)
> Math.floor(date/(86400*1000)) + 1
17349
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment