您的位置:首页 > 编程语言 > Go语言

Golang的time.Unix()函数可能存在的一个BUG

2014-04-09 00:00 381 查看
摘要: 在调用time.Unix()时,我本来是想确定math.MaxInt64,最大能表示的日期是多少,最后发现转换出来的字符串日期不是完全正确,请看代码的执行结果。问题可能出在time转换部分,或出现在字符串装换部分,总之这应该是一个BUG。

fmt.Printf("math.MaxInt64            to time.Unix=[%s]\n", time.Unix(math.MaxInt64, 0))
fmt.Printf("math.MaxInt64/10         to time.Unix=[%s]\n", time.Unix(math.MaxInt64/10, 0))
fmt.Printf("math.MaxInt64/100        to time.Unix=[%s]\n", time.Unix(math.MaxInt64/100, 0))
fmt.Printf("math.MaxInt64/1000       to time.Unix=[%s]\n", time.Unix(math.MaxInt64/1000, 0))
fmt.Printf("math.MaxInt64/10000      to time.Unix=[%s]\n", time.Unix(math.MaxInt64/10000, 0))
fmt.Printf("math.MaxInt64/100000     to time.Unix=[%s]\n", time.Unix(math.MaxInt64/100000, 0))
fmt.Printf("math.MaxInt64/1000000    to time.Unix=[%s]\n", time.Unix(math.MaxInt64/1000000, 0))
fmt.Printf("math.MaxInt64/10000000   to time.Unix=[%s]\n", time.Unix(math.MaxInt64/10000000, 0))
fmt.Printf("math.MaxInt64/100000000  to time.Unix=[%s]\n", time.Unix(math.MaxInt64/100000000, 0))
fmt.Printf("math.MaxInt64/1000000000 to time.Unix=[%s]\n", time.Unix(math.MaxInt64/1000000000, 0))

执行结果如下:

math.MaxInt64 to time.Unix=[219250468-12-04 23:30:07 +0800 CST]math.MaxInt64/10 to time.Unix=[-837066640-09-10 09:33:00 +0800 CST]math.MaxInt64/100 to time.Unix=[-1372195080-04-09 08:09:18 +0800 CST]math.MaxInt64/1000 to time.Unix=[292278994-08-17 15:12:55 +0800 CST]math.MaxInt64/10000 to time.Unix=[29229672-06-18 01:31:17 +0800 CST]math.MaxInt64/100000 to time.Unix=[2924740-04-01 00:09:07 +0800 CST]math.MaxInt64/1000000 to time.Unix=[294247-01-10 12:00:54 +0800 CST]math.MaxInt64/10000000 to time.Unix=[31197-09-14 10:48:05 +0800 CST]math.MaxInt64/100000000 to time.Unix=[4892-10-08 05:52:48 +0800 CST]math.MaxInt64/1000000000 to time.Unix=[2262-04-12 07:47:16 +0800 CST]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Golang time.Unix BUG