Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

Javascript Date seemingly not giving proper hour

Okay, newbie JavaScript question. I am constructing a Date object from a string. This string to construct the Date is 2020-08-19T11:32:08 but the output of toISOString() is 2028-08-19T15:32:08.000Z Why am I seeing the hour as 15 instead of 11?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

2020-08-19T11:32:08 is your local time - in your timezone.

2028-08-19T15:32:08.000Z is the universal time (indicated by the Z at the end) - that's the time on the GMT/UTC. It's right in UK in winter, but otherwise the use of this is that we can all agree to use the same timezone when sharing times internationally.

If you only have local users all in the same timezone it's probably a can of worms you don't want to open. If you have international users and you want them to interact (for instance book a video meeting between New York and LA) then the convention is to use UTC dates (blame the British empire for that one).

ISO is the standard format and toISOString also uses the UTC timezone.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...