Go和Javascript时间戳差异

问题描述 投票:0回答:2

为什么javascript的时间戳与Go的时间戳不同?

const date = new Date(new Date("2019-12-27T15:04:03").toUTCString());
date.getTime() //1577455443000
datetime := "2019-12-27T15:04:03Z"
t, _ := time.Parse(time.RFC3339, datetime)
fmt.Println(t.UTC().UnixNano() / 1000000) // 1577459043000

防止这种分歧的正确方法是什么?

javascript datetime go timestamp utc
2个回答
0
投票

Java时间是将本地时间15:04:03转换为UTC。

开始时间是世界标准时间15:04:03。


0
投票
javascript中的[[getTime())返回自Unix纪元以来的

毫秒的数目,如此处所述:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime

UnixNano()in go返回自Unix纪元以来经过的

nanoseconds

数,如此处所述:https://godoc.org/time#Time.UnixNano
© www.soinside.com 2019 - 2024. All rights reserved.