// 时间戳转日期格式
t := time.Now().Unix()
fmt.Println("t:", t)
t2 := time.Unix(t, 0).Format("2006-01-02 15:04:05")
fmt.Println("t2:", t2)
// 日期格式转时间戳
t3, _ := time.Parse("2006-01-02 15:04:05", t2)
fmt.Println("t3:", t3)
t4 := t3.Unix()
fmt.Println("t4:", t4)
输出结果:
t: 1574923180
t2: 2019-11-28 14:39:40
t3: 2019-11-28 14:39:40 +0000 UTC
t4: 1574951980