Reputation: 213
I've a data which I'm trying to convert to unix timestamp but I think my rfc3339 data coming from server is not proper.
data:='2020-07-08T01:11:02-0700'
startDate, err := time.Parse(time.RFC3339, data.(string))
if err != nil {
fmt.Println("err is", err)
return
}
This is the error I'm getting
err is parsing time "2020-07-08T01:11:02-0700" as "2006-01-02T15:04:05Z07:00": cannot parse "-0700" as "Z07:00".
What is a proper rfc format or how should I change my output in a way that this function could work and then I can convert this to timestamp?
Upvotes: 1
Views: 7654
Reputation: 7431
The issue is in time offset format. You have -0700
which is not compliant with RFC3339. You need to pass -07:00
. See time-numoffset
format in grammar here.
For time format you have you need to pass following custom layout so it parses the offset correctly:
data := "2020-07-08T01:11:02-0700"
startDate, err := time.Parse("2006-01-02T15:04:05-0700", data)
Upvotes: 3