如何加载 UTC 数字日期并将其转换为 unix +new Date()?
how to load a UTC numeric date and convert it to a unix +new Date()?
我正在使用 coingecko api 他们说 -
Timestamps returned by this API are in UTC Timezone.
我正在拨打的电话:
'https://api.coingecko.com/api/v3/coins/'+'dash'+'/ohlc?vs_currency='+'eur'+'&days=365'
例如,今天的时间戳(我认为)应该是 1579046400000
:
new Date(1579046400000)
Wed Jan 15 2020 00:00:00 GMT+0000 (Western European Standard Time)
但是今天是:
+new Date()
1610300187790
Sun Jan 10 2021 17:36:27 GMT+0000 (Western European Standard Time)
我正在查看 javascript https://www.quackit.com/javascript/javascript_date_and_time_functions.cfm
中的 Date 对象
我很困惑。 如何将此 UTC 时间戳转换为普通的 unix 时间戳?
我什至不明白UTC是什么格式,是毫秒吗? (对我来说好像是秒)
我能找到的所有UTC问题日期都不是这样的! (它们看起来像字符串)
我什至不知道如何将这个数字加载到日期对象中:
new Date().UTC(579046400000)
VM392:1 Uncaught TypeError: (intermediate value).UTC is not a function
at <anonymous>:1:12
(anonymous) @ VM392:1
new Date().toUTCString(579046400000)
"Sun, 10 Jan 2021 18:01:25 GMT"
new Date().
setUTCDate(579046400000)
NaN
Date.UTC(579046400000)
NaN
如何将其加载到日期对象中?
The data is sorted from oldest to youngest. The first entry - which you assumed to be today - is actually the oldest one, roughly 365 days old. The last entry in the list is from today. So new Date(timestamps) is the correct way to handle these dates. (UTC and Unix timestamps are identical for everything after 1972 - I believe) – cuzi
我应该不是阅读障碍
@cuzi 100% 正确!
我正在使用 coingecko api 他们说 -
Timestamps returned by this API are in UTC Timezone.
我正在拨打的电话:
'https://api.coingecko.com/api/v3/coins/'+'dash'+'/ohlc?vs_currency='+'eur'+'&days=365'
例如,今天的时间戳(我认为)应该是 1579046400000
:
new Date(1579046400000)
Wed Jan 15 2020 00:00:00 GMT+0000 (Western European Standard Time)
但是今天是:
+new Date()
1610300187790
Sun Jan 10 2021 17:36:27 GMT+0000 (Western European Standard Time)
我正在查看 javascript https://www.quackit.com/javascript/javascript_date_and_time_functions.cfm
中的 Date 对象我很困惑。 如何将此 UTC 时间戳转换为普通的 unix 时间戳?
我什至不明白UTC是什么格式,是毫秒吗? (对我来说好像是秒)
我能找到的所有UTC问题日期都不是这样的! (它们看起来像字符串)
我什至不知道如何将这个数字加载到日期对象中:
new Date().UTC(579046400000)
VM392:1 Uncaught TypeError: (intermediate value).UTC is not a function
at <anonymous>:1:12
(anonymous) @ VM392:1
new Date().toUTCString(579046400000)
"Sun, 10 Jan 2021 18:01:25 GMT"
new Date().
setUTCDate(579046400000)
NaN
Date.UTC(579046400000)
NaN
如何将其加载到日期对象中?
The data is sorted from oldest to youngest. The first entry - which you assumed to be today - is actually the oldest one, roughly 365 days old. The last entry in the list is from today. So new Date(timestamps) is the correct way to handle these dates. (UTC and Unix timestamps are identical for everything after 1972 - I believe) – cuzi
我应该不是阅读障碍
@cuzi 100% 正确!