为什么Go语言的time.Equal方法没有地点信息?

3
http://golang.org/src/pkg/time/time.go上,有关于时间的IT技术内容。
62  // Equal reports whether t and u represent the same time instant.
63  // Two times can be equal even if they are in different locations.
64  // For example, 6:00 +0200 CEST and 4:00 UTC are Equal.
65  // This comparison is different from using t == u, which also compares
66  // the locations.
67  func (t Time) Equal(u Time) bool {
68      return t.sec == u.sec && t.nsec == u.nsec
69  }

他们为什么不关心t.loc和u.loc?

更新: 如果我有两个服务器(位于不同位置),我该如何判断它们的时间是否完全相等?


4
答案就在上面的Go源代码注释中。 - zzzz
2个回答

10

Time 存储一个 UTC 时间戳,这意味着它不依赖于位置。

时间 6:00 +0200 CEST4:00 UTC 具有相同的 UTC 值。它们是同一时刻。

只有当地化表示此时间时才使用位置。

来自文档

以此方式更改位置仅更改显示;它不会更改时间上的瞬间


1
我没有看到你的答案(比我的早发布1分钟)。向您致敬,先生。 - VonC

4
  • t.sec 给出自公元1年1月1日00:00:00 UTC以来经过的秒数。
  • n.nsec 指定了秒内非负纳秒偏移量,范围为[0, 999999999]。

这个UTC时间与位置无关。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接