gpt4 book ai didi

戈朗 : convert milliseconds to time

转载 作者:IT王子 更新时间:2023-10-29 01:35:44 25 4
gpt4 key购买 nike

无论时区如何,我都需要将毫秒转换为时间。下面是示例代码

我 := 1481462220
tm := 时间.Unix(i, 0)

当前时间。Unix 返回特定于我的机器区域的时间。因此,如果我更改机器的时区,它会返回不同的时间。 我需要的是无论机器的时区如何,时间都应该相同。

最佳答案

根据 GoDoc 时间.Unix :

Unix returns the local Time corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC.

因此,要获得跨机器的相同时间,您需要使用 time.Time.UTC() 转换返回的本地时间

所以在这种情况下它将是 tm.UTC()

关于戈朗 : convert milliseconds to time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41037191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com