Getting current date in milliseconds (UTC) (NO use of strings)

前端 未结 5 2126
梦如初夏
梦如初夏 2021-02-18 18:35

Well, you might think that this question has already been asked, but I think it has not. The solutions I\'ve read about all had this \"jigsaw puzzle\" technique (like getU

5条回答
  •  伪装坚强ぢ
    2021-02-18 19:04

    The millisecond value of the time-of-day is going to be the same regardless of your time zone. That is, there are no time zones on planet Earth that differ from one another by a number of milliseconds greater than zero. (They may differ by an integer number of hours or even minutes, but not seconds or milliseconds.)

    That said, the value you get back from getTime() is a UTC-relative timestamp. If two web browsers at widely different spots on the globe create a Date object at the same time, they'll both get the same value from .getTime() (assuming the clocks are synchronized, which is of course highly unlikely).

    Here: 1338585185539 That's a timestamp I just got from my browser. I'm in Austin, TX, and now it's 4:13 in the afternoon (so that timestamp will be from slightly before that). Plug it into a Date instance on your machine and see what it says.

    (edit — for posterity's sake, that timestamp is from 1 June 2012.)

提交回复
热议问题