time.Unix(t, offset) 给出相同的时间?
time.Unix(t, offset) gives same time?
尝试使用以下 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
请问这是什么问题?为什么 hour:minute 没有变化? (04:40)
go version go1.15.6 linux/amd64
您正在更改纳秒和打印分钟...
https://pkg.go.dev/time@go1.16.7#Unix
func Unix(sec int64, nsec int64) Time
检查这个:
https://play.golang.org/p/_Ywn9S5Khch
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 ---- %2d\n", ts+i, t.Hour(), t.Minute(), t.UnixNano())
}
}
尝试使用以下 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
请问这是什么问题?为什么 hour:minute 没有变化? (04:40)
go version go1.15.6 linux/amd64
您正在更改纳秒和打印分钟...
https://pkg.go.dev/time@go1.16.7#Unix
func Unix(sec int64, nsec int64) Time
检查这个: https://play.golang.org/p/_Ywn9S5Khch
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 ---- %2d\n", ts+i, t.Hour(), t.Minute(), t.UnixNano())
}
}