Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time: doesn't parse RFC3339 properly #9346

aniketawati opened this issue Dec 16, 2014 · 5 comments

time: doesn't parse RFC3339 properly #9346

aniketawati opened this issue Dec 16, 2014 · 5 comments


Copy link

@aniketawati aniketawati commented Dec 16, 2014

Time can't parse the layout constant for RFC3339 in the code itself.

For eg. Go playground link -

    // Time value taken from go source
    layout := "2006-01-02T15:04:05Z07:00" // RFC3339
    tm, err := time.Parse(layout, layout) 
    if err != nil {
        fmt.Println("error", err)
    fmt.Println("Parsed time", tm)

Currently if there is any offset in time (non UTC time), time formats it in RFC3339 as - +07:00 instead of Z07:00

If Z07:00 is given, it gives an error

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

Copy link

@nickcarenza nickcarenza commented May 26, 2015

@aniketawati How did you resolve this?

Copy link

@firba1 firba1 commented Aug 26, 2015

For posterity: the time package docs describe this layout conversion with the Z (near the bottom of the linked section), which is that it shows "Z" instead of a time offset if the timezone is UTC, and +hh:mm or -hh:mm otherwise. Since this is one of the few examples of the reference time format not being an actually valid time, I can see the confusion.

@mikioh mikioh changed the title time doesn't parse RFC3339 properly time: doesn't parse RFC3339 properly Aug 29, 2015
Copy link

@mdwhatcott mdwhatcott commented Sep 15, 2015

Maybe the docs should be updated to reflect the insight shared by @firba1 ??

Copy link

@ianlancetaylor ianlancetaylor commented Sep 15, 2015

@mdwhatcott firba1 is citing the docs, so I'm not sure what to change. I would encourage you to send in a change if you see how to make the docs better (

Copy link

@mdwhatcott mdwhatcott commented Sep 15, 2015

Thanks for the encouragement @ianlancetaylor. I received a good answer on stackoverflow just today that was more helpful for me than the docs, probably because it used complete real examples and was specific to the particular layout string I was using:

The time.RFC3339 format is a case where the format string itself isn't a valid time. You can't have a Z and an offset in the time string, but the format string has both because the spec can contain either type of timezone specification.

Both of these are valid RFC3339 times:


And the time package needs to be able to parse them both using the same RFC3339 format string.

@golang golang locked and limited conversation to collaborators Sep 22, 2016
gopherbot pushed a commit that referenced this issue Dec 6, 2017
For #9346 #22135 explicitly state under layout constants
that they are not valid time values for Parse. Also add
examples of parsing valid RFC3339 values and the layout
to the example for time.Parse.

Fix capitalisation of time.Parse and Time.Format.

For #20869 include RFC3339 in the list of layouts that do
not accept all the time formats allowed by RFCs (lowercase z).
This does not fully address #20869.

Fixes #9346
Fixes #22135

Change-Id: Ia4c13e5745de583db5ef7d5b1688d7768bc42c1b
Run-TryBot: Ian Lance Taylor <>
TryBot-Result: Gobot Gobot <>
Reviewed-by: Ian Lance Taylor <>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.