时间。Unix(t,偏移量)给出相同的时间?

尝试使用下面的 Go 代码获取连续的时间戳


package main


import "fmt"

import "time"


func main () {

    ts := int64(1500000000)  // start

    for i := int64(0); i<1e6; i = i + 1000 { // successively add 1e3

            t := time.Unix(ts, i)  // Get start + i

            fmt.Printf("%d %02d:%02d\n", ts+i, t.Hour(), t.Minute())

    }

}

,输出仍然像


....

1500995000 04:40

1500996000 04:40

1500997000 04:40

1500998000 04:40

1500999000 04:40

拜托,这里有什么问题?为什么小时:分钟不变化?(04:40)


go version go1.15.6 linux/amd64


POPMUISE
浏览 56回答 1
1回答

交互式爱情

您正在更改纳秒和打印分钟...https://pkg.go.dev/time@go1.16.7#Unixfunc&nbsp;Unix(sec&nbsp;int64,&nbsp;nsec&nbsp;int64)&nbsp;Time检查这个:&nbsp;https://play.golang.org/p/_Ywn9S5Khchpackage mainimport "fmt"import "time"func main () {&nbsp; &nbsp; ts := int64(1500000000)&nbsp; // start&nbsp; &nbsp; for i := int64(0); i<1e6; i = i + 1000 { // successively add 1e3&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t := time.Unix(ts, i)&nbsp; // Get start + i&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fmt.Printf("%d %02d:%02d ---- %2d\n", ts+i, t.Hour(), t.Minute(), t.UnixNano())&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go