package main
import (
"fmt"
"time"
)
func main() {
FORMAT := "2006-01-02 15:04:05"
a := time.Now()
fmt.Println("Now:", time.Now().Format(FORMAT))
fmt.Println("A:", a.Format(FORMAT), a.Unix(), a.UnixNano())
fmt.Println("\nSleep...\n")
time.Sleep(time.Second * 10)
fmt.Println("Now:", time.Now().Format(FORMAT))
b := a.Add(5 * time.Hour)
c := time.Now()
fmt.Println("B:", b.Format(FORMAT), b.Unix(), b.UnixNano())
fmt.Println("C:", c.Format(FORMAT), c.Unix(), c.UnixNano())
if b.After(c) {
fmt.Println("After,B after C")
} else {
fmt.Println("After,B is not after C")
}
if b.Unix() >= c.Unix() {
fmt.Println("Unix,B after C")
} else {
fmt.Println("Unix,B is not after C")
}
if b.UnixNano() >= c.UnixNano() {
fmt.Println("UnixNano,B after C")
} else {
fmt.Println("UnixNano,B is not after C")
}
}
Go version:
go version go1.14.1 windows/amd64
go version go1.15.6 windows/amd64
When sleeping,modify system time(add one day),‘After’ function return true?
Why?