问题描述
Format以后输出的时间与now是不一样的
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
fmt.Println(now)
format := now.Format("2006-01-01 15:04:05")
fmt.Println(format)
}
解决办法
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
fmt.Println(now)
format := now.Format("2006-01-02 15:04:05")
fmt.Println(format)
}
使用time.Format格式化时间参数layout必须要传"2006-01-02 15:04:05",为什么呢?没有为什么,这就是最坑的地方,据说这个日期是GO语言的诞生时间,格式化时就必须要传这个时间,传其他的时间都会有问题.