Why does the same date have different hours?

前端 未结 3 1986
余生分开走
余生分开走 2021-01-22 20:16

Maybe the answer is obvious, but I don\'t get it. Why are the Dates in the Code Snippet different? Does the format say something about the hours as well?

3条回答
  •  情深已故
    2021-01-22 20:41

    The dates being displayed are using different timezones. The Chrome console output is using your browsers local timezone and adjusting it appropriately. The (GMT+0100) is telling you which timezone and adjustments that are being made. The code snippet console is displaying using UTC. The 'Z' at the end of the string signifies that.

    If you want to convince yourself of that they are the same, print the timestamp for each date also. This is also why when you are dealing with dates, you should rely on timestamps rather than comparing dates like this. Things get very confusing and difficult to deal with.

提交回复
热议问题