代码如下
package main
import (
"fmt"
"sync"
"time"
)
func main() {
const FORMAT = "2006-01-02 15:04:05"
var a = new(sync.Map)
b := time.Now()
fmt.Println(b.Location())
a.Store("a", b)
//c, _ := a.Load("a")
fmt.Println(b.Format(FORMAT))
time.Sleep(time.Second * 10)
after := time.Hour * 5
//t, ok := c.(time.Time); ok &&
t := b
if t.Add(after).After(time.Now()) {
fmt.Println(t.Unix(), "\n", time.Now().Unix())
fmt.Println(t.Add(after).Format(FORMAT), " 大于 ", time.Now().Format(FORMAT))
} else {
fmt.Println(t.Add(after).Format(FORMAT), " 小于 ", time.Now().Format(FORMAT))
}
}
执行到time.Sleep(time.Second * 10)
时如果修改当前时间为1天后,下面的After会判断错误,下面是输出结果
Local
2019-07-11 08:45:23
1562805923
1562856331
2019-07-11 13:45:23 大于 2019-07-11 22:45:31
如果t加上Local就没有问题,t.After函数的判断方式有问题
有疑问加站长微信联系(非本文作者)