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: Parse() does not recognize time zone MST #19694

crufter opened this issue Mar 24, 2017 · 3 comments

time: Parse() does not recognize time zone MST #19694

crufter opened this issue Mar 24, 2017 · 3 comments


Copy link

@crufter crufter commented Mar 24, 2017

What version of Go are you using (go version)?

Playground one, go version go1.8 darwin/amd64, go version go1.7.3 darwin/amd64, it's all wrong on these.

What operating system and processor architecture are you using (go env)?

The go env correspoding to the go version go1.7.3 darwin/amd64 version:

GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/nm/gx94478n3dq9478jm5ndvpqh0000gn/T/go-build541649718=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I put the example code from the time.Parse docs on playground and I see a different output than the output in the doc.

What did you expect to see?

2013-02-03 19:54:00 -0800 PST

(Same as in documentation here:

What did you see instead?

2013-02-03 19:54:00 +0000 PST

Copy link

@ALTree ALTree commented Mar 24, 2017

The Parse documentation says:

When parsing a time with a zone abbreviation like MST, if the zone abbreviation has a defined offset in the current location, then that offset is used.


If the zone abbreviation is unknown, Parse records the time as being in a fabricated location with the given zone abbreviation and a zero offset


To avoid such problems, prefer time layouts that use a numeric zone offset, or use ParseInLocation

So you can either use the numeric offset, or call ParseInLocation:

loc, _ := time.LoadLocation("US/Pacific")
const longForm = "Jan 2, 2006 at 15:04 (MST)"
t, _ := time.ParseInLocation(longForm, "Feb 3, 2013 at 19:30 (PST)", loc)

2013-02-03 19:30:00 -0800 PST

I guess in the documentation it recognizes PST as -08 because it's the godoc tz?

Copy link

@ianlancetaylor ianlancetaylor commented Mar 24, 2017

Which timezones are recognized depends on the timezone database on your computer.

Timezone names are inherently ambiguous and should be avoided when possible for portability.

Closing because I don't think there is anything to do. Please comment if you disagree.

Copy link

@crufter crufter commented Mar 29, 2017

@ianlancetaylor @ALTree

That explanation makes sense. I did not realise the timezone database is on my computer, hence I found the disparity between my setup and weird.

Thank you

@golang golang locked and limited conversation to collaborators Mar 29, 2018
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
4 participants
You can’t perform that action at this time.