golang json.Unmarshal not support time format 2006-01-02T15:04:05.999999999+0700

1,974 views
Skip to first unread message

Lee Rick

unread,
Jul 16, 2018, 11:20:22 PM7/16/18
to golang-nuts
dear 
      a []byte has a filed "createime" : "2018-07-05T09:55:16.000+0000",  the value of createime is a time format,  i define a struct like  "type a struct{ Createime time.Time `json:"createime"`}"
     when i use json.Unmarshal parse it, it fail and output not support 
      i search golang standard package, and find that golang support the two flowlling time format
      RFC3339 = "2006-01-02T15:04:05Z07:00  RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00"
  ,but not find const RFC3339NanoZ = "2006-01-02T15:04:05.999999999+0700"
   
   anyone can tell me how to make it works?
  

Lee Rick

unread,
Jul 17, 2018, 12:56:39 AM7/17/18
to golang-nuts

err info

parsing time ""2018-07-17T04:36:55.000+0000"" as ""2006-01-02T15:04:05Z07:00"": cannot parse "+0000"" as "Z07:00"



在 2018年7月17日星期二 UTC+8上午11:20:22,Lee Rick写道:

Constantin Konstantinidis

unread,
Jul 17, 2018, 5:24:27 AM7/17/18
to golang-nuts
The issue was reported here https://github.com/golang/go/issues/5016
I don't know if this is workable for you.

roger peppe

unread,
Jul 17, 2018, 8:58:18 AM7/17/18
to Lee Rick, golang-nuts
Your time zone isn't in standard RFC3339 format (it's missing a
colon). You can parse your timestamps
if you use time.Parse with a layout value of "2006-01-02T15:04:05Z0700".
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages