2013-03-18 91 views
4

日期和時間的整個概念是非常片斷和不斷更新,所以從一開始這是一個非常艱鉅的任務。從閏年到閏秒,需要考慮如此多的變量。Go編程語言如何處理日期和時間?

約翰Skeet的圖書館看起來不錯,但他已經花了3年的時間把它變得這麼遠,它還很不完美。

有人能給我一個關於Go編程語言如何處理DateTime與其他語言/庫相比具有不同或相似性的指示嗎?這純粹是出於好奇的緣故。

這個問題更多地關於當前可用庫的相似之處和差異 - 最好用英文,而不是頁面和文檔頁面。

+0

http://golang.org/pkg/time/ – lzcd 2013-03-18 06:18:21

回答

7

看到time package文檔和源代碼。 A 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 
} 
+0

它是否完全考慮了某些國家/地區缺少的時區,周等? – SamuelDavis 2013-03-18 07:05:39

+0

有關IANA時區數據庫的信息(包括實施細節)在代碼庫中進行了描述。 – peterSO 2013-03-18 07:17:37

+0

另一個關於Go中的'time'軟件包的好處是沒有「Data」或「DateTime」類型。它只有一個'時間',代表一個時間點(當然,精度有限)。 – Mostafa 2013-03-18 10:38:17