-4

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

MenyT
  • 1,653
  • 1
  • 8
  • 19
dwlpra
  • 76
  • 7
  • What have you tried? What went wrong? – Volker Sep 22 '21 at 10:37
  • 2
    Does this answer your question? [How to format current time using a yyyyMMddHHmmss format?](https://stackoverflow.com/questions/20234104/how-to-format-current-time-using-a-yyyymmddhhmmss-format) – Bracken Sep 22 '21 at 17:11

2 Answers2

1

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

MenyT
  • 1,653
  • 1
  • 8
  • 19
0
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"))
}
p1gd0g
  • 631
  • 5
  • 16