戈朗 : convert milliseconds to time

标签 go time

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

我 := 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/

相关文章:

go - 在 Go 中通过 STOMP 连接到 ActiveMQ

C -一系列 if 语句与 else if 时间测量

c++ - 打印时间到 std::ostream

php - 在 PHP 中减去日期

java - Android:深度 sleep 的时间间隔(System.nanoTime(), System.currentTimeMillis(), SystemClock.elapsedRealtimeNanos())

linux - Linux 中的时间变量地址

go - 使用反射设置指针值?

struct - 如何在没有反射的情况下将结构转储到字节数组中?

android - 用于在 GAE 上运行的 Go 中验证 Google 登录 token 的包

mysql - 在mysql foreach中转换为Markdown并添加到数组