2012-10-12 24 views
3

http://golang.org/src/pkg/time/time.go为什么没有在golang时间的工作人员。等于?

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?

更新: 如果我有2台服务器(不同地点),以及如何我可以判断,如果他们的时间正好等于

+4

答案在上面的Go源代码评论中是正确的。 – zzzz

回答

10

一个Time店的UTC时间戳?这意味着它不依赖于位置。

时间6:00 +0200 CEST4:00 UTC具有相同的值UTC。他们是完全相同的时刻。

该位置仅用于此次的本地化表示。

the documentation

这样的变化仅呈现更改位置;它不会改变的时间瞬间

+1

我没有看到你的答案(我的1分钟前发表)。先生,先生+1。 – VonC

4
  • t.sec给出了今年1 00:00:00 UTC自1月1日经过的秒数。
  • n.nsec指定秒内由秒命名的非负纳秒偏移量。 (范围[0,999999999])

UTC time不取决于位置。

相关问题