golang get date year month day

date := time.Now().Format(“2006-01-02 15:04:05”)

Only by writing the above parameters can the corresponding time format be obtained, so we can also use this method to obtain the year, month, day, hour, minute and second of the current time.

year:=time.Now().Year()
month := time.Now().Format(“01”)
day:=time.Now().Day()
//

year := time.Now().Format(“2006”)
month := time.Now().Format(“01”)
day := time.Now().Format(“02”)
hour := time.Now().Format(“15”)
min := time.Now().Format(“04”)
second := time.Now().Format(“05”)

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEnglish