golang 获取日期年月日

时间:2025-03-02 08:12:58

众所周知Golang的时间格式化很奇怪

date := ().Format("2006-01-02 15:04:05")

只有写以上参数才可获得对应的时间格式,所以我们也可以利用这个方法获取当前时间的年月日时分秒

year:=().Year()
month := ().Format("01")
day:=().Day()
//或者

year := ().Format("2006")
month := ().Format("01")
day := ().Format("02")
hour := ().Format("15")
min := ().Format("04")
second := ().Format("05")