Time Parsing

635 views
Skip to first unread message

Ulrich Schreiner

unread,
Jul 27, 2011, 6:44:23 AM7/27/11
to golan...@googlegroups.com
hi,

i'm writing a simple program to query data from the google spreadsheet api. in the result of a feed there is a field

<updated>2011-07-27T10:29:03.925Z</updated>

in the reference this timestamp is described as RFC3339. so i tried to parse it with 

time.Parse (time.RFC3339, "2011-07-27T10:29:03.925Z")

but

Error: parsing time "2011-07-27T10:29:03.925Z" as "2006-01-02T15:04:05Z07:00": cannot parse ".925Z" as "Z07:00"

yes, google returns a fraction in the seconds! ok, now i tried the following:

time.Parse (time.RFC3339, time.RFC3339)

and oops:

Error: parsing time "2006-01-02T15:04:05Z07:00": extra text: 07:00

shouldn't the Parse-Function be able to parse the format? is this a bug or am i'm doing something completely wrong? 

thank you
</usc>

roger peppe

unread,
Jul 27, 2011, 6:48:57 AM7/27/11
to golan...@googlegroups.com
ParseTime can't deal with fractional seconds. It's mentioned in issue 1594,
and might be fixed at some point in the future, I guess.

Kyle Lemons

unread,
Jul 27, 2011, 1:39:05 PM7/27/11
to golan...@googlegroups.com
I can't find it quickly, but I got around this by ripping the fractional seconds out of a time using regexp, passing most of the stamp to time.Parse and the fractional seconds to strconv.Atoi and then combining them.  This may work for you.
~K

Ulrich Schreiner

unread,
Jul 28, 2011, 2:16:42 AM7/28/11
to golan...@googlegroups.com
I'm doing it this way. 

not a real problem but it was a surprise, that the pattern "time.RFC3339" cannot parse the string "time.RFC3339" :-)
Reply all
Reply to author
Forward
0 new messages