1、时间戳转日期:
timestamp := 1602482956
timeobj := time.Unix(int64(timestamp), 0)
date := timeobj.Format("2006-01-02 15:04:05")
fmt.Println(date)
运行结果:
2、日期转时间戳:
str := "2020-10-12 14:19:53"
tmp := "2006-01-02 15:04:05"
res, _ := time.ParseInLocation(tmp, str, time.Local)
fmt.Println(res.Unix())