go 去除时间的时分秒
实现
如 2021-12-18 12:14:16 格式化为 2021-12-18 00:00:00
func main() {
timeNow := time.Now()
timeNowStr := timeNow.Format("2006-01-02 15:04:05")
fmt.Println("timeNowStr:", timeNowStr)
// 方式一
timeDateStr := timeNow.Format("2006-01-02 00:00:00")
fmt.Println("timeDateStr:", timeDateStr)
// 方式二
y, m, d := timeNow.Date()
date := time.Date(y, m, d, 0, 0, 0, 0, time.Local)
dateStr := date.Format("2006-01-02 15:04:05")
fmt.Println("dateStr:", dateStr)
}