-2

I have func use to get hour .

func GetHourFromAPI(lastUpdate string) int   {
    t, err := time.Parse(time.RFC3339, lastUpdate)
    var hourTime = t.Hour()
    if err != nil {
        fmt.Println(err)
    }
    return hourTime
}

lastUpdate is type string like this : "20190925141100" I tried parse lastUpdate with type RFC3339 and get hour . But , system return t= 0001-01-01 00:00:00 +0000 . My issue at time.Parse ? what i am missing ?

Doctor Strange
  • 37
  • 1
  • 2
  • 10

1 Answers1

2

Your date string isn't compatible with RFC3339 ("2006-01-02T15:04:05Z07:00") as it has no - or : or timezone. You would need to use the format string "20060102150405" and do it like this:

https://play.golang.org/p/_aE-7VDuWV-

date := "20190925141100"
t, err := time.Parse("20060102150405", date)
if err != nil {
    fmt.Println("parse error", err.Error())
}
fmt.Println(t)
dave
  • 62,300
  • 5
  • 72
  • 93