I have a slice of values holding timestamps of different length. Most of them look like this:
2006-01-02T15:04:05.000000Z
but some of them are shorter:
2006-01-02T15:04:05.00000Z
2006-01-02T15:04:05.0000Z
If I do:
str := dataSlice[j][0].(string)
layout := "2006-01-02T15:04:05.000000Z"
t, err := time.Parse(layout, str)
I get errors like:
parsing time "2016-10-23T02:38:45.25986Z" as "2006-01-02T15:04:05.000000Z": cannot parse "" as ".000000"
parsing time "2016-10-23T21:43:59.0175Z" as "2006-01-02T15:04:05.000000Z": cannot parse ".0175Z" as ".000000"
I want to parse them exactly like they originally are. How can I dynamically switch the layout corresponding to the length? (And why do the error messages differ?)