最近对接数据遇到ISO-8601时间格式需要输出,但是time包里面没有,需要自己定义,如下:
package mainimport ( "fmt" "time")var FormatISOTime = "2006-01-02T15:04:05.000Z07:00"var FormatISOTimeoOmitted = "2006-01-02T15:04:05.999Z07:00"func main() { t := time.Now() fmt.Println("====0填充") fmt.Println(t.Format(FormatISOTime)) fmt.Println("====0忽略") fmt.Println(t.Format(FormatISOTimeoOmitted))}
➜ t go run main.go====0填充2021-12-08T22:37:18.240+08:00====0忽略2021-12-08T22:37:18.24+08:00