常用时间方法
1. 当前时间
now := time.Now()
fmt.Println(now , reflect.TypeOf(now)) // 类型 time.Time
2. 当前时间字符串格式
nowStr := time.Now().Format("2006-01-02 15:04:05") // 2006-01-02 15:04:05 固定
3 当前时间戳
timestamp := time.Now().Unix() // int64
时间戳 (timestamp) 与时间 (time) 互转
1. 时间戳 转 时间类型
timestamp_to_time := time.Unix(timestamp, 0)
2. 时间类型 转 时间戳
time_to_timestamp := now.Unix()
时间戳 (timestamp) 与时间字符串 (string) 互转
1. 时间戳 转 字符串
timestamp_to_str := time.Unix(timestamp, 0).Format("2006-01-02 15:04:05")
2. 字符串 转 时间戳
str := "2018-08-08 11:11:11"
str_to_time, _ := time.Parse("2006-01-02 15:04:05", str)
time_to_timestamp := str_to_time.Unix()
时间 (time) 与时间字符串 (string) 互转
1. time 转 字符串
time_to_str := now.Format("2006-01-02 15:04:05")
2. 字符串 转 time
str := "2018-08-08 11:11:11"
str_to_time, _ := time.Parse("2006-01-02 15:04:05", str)