I have been fighting with this for a bit now.
(我现在一直在与此斗争。)
I'm trying to convert epoch to a date object.(我正在尝试将纪元转换为日期对象。)
The epoch is sent to me in UTC.(这个时代以UTC的形式发送给我。)
Whenever you pass new Date()
an epoch, it assumes it's local epoch.(每当你传递一个new Date()
时代时,它就会假定它是本地时代。)
I tried creating a UTC object, then using setTime()
to adjust it to the proper epoch, but the only method that seems useful is toUTCString()
and strings don't help me.(我尝试创建一个UTC对象,然后使用setTime()
将其调整到正确的纪元,但唯一有用的方法是toUTCString()
和字符串对我toUTCString()
。)
If I pass that string into a new date, it should notice that it's UTC, but it doesn't.(如果我将该字符串传递给新的日期,它应该注意到它是UTC,但事实并非如此。)
new Date( new Date().toUTCString() ).toLocaleString()
My next attempt was to try to get the difference between local current epoch and UTC current epoch, but I wasn't able to get that either.
(我的下一次尝试是尝试获取当地当前时期和UTC当前时期之间的差异,但我也无法得到它。)
new Date( new Date().toUTCString() ).getTime() - new Date().getTime()
It's only giving me very small differences, under 1000, which is in milliseconds.
(它只给了我很小的差异,低于1000,这是毫秒。)
Any suggestions?
(有什么建议?)
ask by Shane Reustle translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…