Go编程语言如何处理日期和时间?

时间:2013-03-18 06:16:44

标签: date datetime time go

日期和时代的整个概念令人难以置信地不断变化,并且不断更新,因此从一开始就是一项非常困难的任务。从闰年到闰秒,需要考虑很多变量。

John Skeet的图书馆看起来不错,但已经花了他3年的时间来实现这一目标,而且还远未完美。

有人可以告诉我Go编程语言与其他语言/库相比如何处理DateTime的方式不同或类似吗?这纯粹是为了好奇。

这个问题更多的是关于当前可用库之间的相同点和不同点 - 最好是英文版,而不是页面和文档页面。

1 个答案:

答案 0 :(得分:7)

请参阅Go time package文档和源代码。 Time表示具有纳秒精度的瞬间,没有闰秒。 IANA Time Zone Database用于时区和夏令时。时区数据库包含代表全球许多代表性地点的当地时间历史的代码和数据。它会定期更新,以反映政治机构对时区边界,UTC偏移和夏令时规则所做的更改。

type Time struct {
    // sec gives the number of seconds elapsed since
    // January 1, year 1 00:00:00 UTC.
    sec int64

    // nsec specifies a non-negative nanosecond
    // offset within the second named by Seconds.
    // It must be in the range [0, 999999999].
    nsec int32

    // loc specifies the Location that should be used to
    // determine the minute, hour, month, day, and year
    // that correspond to this Time.
    // Only the zero Time has a nil Location.
    // In that case it is interpreted to mean UTC.
    loc *Location
}
相关问题