I have date time with format 18/09/21 14.56 from excel. I want to parse and format to different format 2006-01-02 hh:mm:ss
Is possible to parse time with format 18/09/21 14.56 in golang and then format it to eg. 2006-01-02 hh:mm:ss
I have date time with format 18/09/21 14.56 from excel. I want to parse and format to different format 2006-01-02 hh:mm:ss
Is possible to parse time with format 18/09/21 14.56 in golang and then format it to eg. 2006-01-02 hh:mm:ss
Golang use example based template for Parse
and Format
.
01 -> month with zero prefix
02 -> day with zero prefix
06 -> year (last two digits)
15 -> hour (24h based)
04 -> minutes with zero prefix
05 -> seconds with zero prefix
2006 -> long year
t, _ := time.Parse("02/01/06 15.04", "18/09/21 14.56")
t.Format("2006-01-02 15:04:05") // 2021-09-18 14:56:00
For more layout options see https://stackoverflow.com/a/69338568/12301864
func TestTime(t *testing.T) {
tm, err := time.Parse("06/01/02 15.04", "18/09/21 14.56")
if err != nil {
return
}
log.Println(tm.Format("2006-01-02 15:04:05"))
}