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: cannot parse GMT timezones with colon-separated offsets #9881

DanielHeath opened this issue Feb 15, 2015 · 3 comments


None yet
5 participants
Copy link

commented Feb 15, 2015

go version
go version go1.4 linux/amd64

uname -a
Linux daniel-linux 3.16.0-28-generic #38-Ubuntu SMP Fri Dec 12 17:37:40 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

This program shows my attempt to parse the time:

I've traced it to src/time/format.go, which consumes any integers following the letters GMT.

The minutes (after the colon) then cause a parse failure.

Because the letters GMT are treated specially, I don't think it's possible to parse this time with the time package.

@minux minux changed the title Time package: Cannot parse GMT timezones with colon-separated offsets time: cannot parse GMT timezones with colon-separated offsets Feb 15, 2015

@ianlancetaylor ianlancetaylor added this to the Go1.5 milestone Feb 20, 2015


This comment has been minimized.

Copy link

commented Jul 22, 2015

I apologize for not picking up this issue earlier, but it is now too late to fix for the 1.5 release: it would be unwise to change the internals of time.Parse and time.Format at this late date. I will mark it to be addressed early in the 1.6 release cycle.

@robpike robpike modified the milestones: Go1.6Early, Go1.5 Jul 22, 2015


This comment has been minimized.

Copy link

commented Sep 25, 2015

Unfortunate. The special handling of GMT, which is needed for other things, makes it very difficult to know whether the :10:00 should be considered part of the time zone or left alone to match the layout.

@robpike robpike closed this Sep 25, 2015


This comment has been minimized.

Copy link

commented Jul 6, 2016

A workaround I used in my project, in case anyone finds it useful -

in1 := "Mon, 4 Jul 2016 16:13:17 +0830 (GMT+08:30)"
in2 := "Mon, 4 Jul 2016 16:13:17 -0500 (GMT-0500)"

regGMTTimezone := regexp.MustCompile(`(?i)GMT([+-]\d{2}:?\d{2}]?)`)

out1 := regGMTTimezone.ReplaceAllString(in1, "$1")
out2 := regGMTTimezone.ReplaceAllString(in2, "$1")


f1 := "Mon, 2 Jan 2006 15:04:05 -0700 (-07:00)"
f2 := "Mon, 2 Jan 2006 15:04:05 -0700 (-0700)"

if t1, err := time.Parse(f1, out1); err == nil {
if t2, err := time.Parse(f2, out2); err == nil {


Mon, 4 Jul 2016 16:13:17 +0830 (+08:30)
Mon, 4 Jul 2016 16:13:17 -0500 (-0500)
04 Jul 16 07:43 UTC
04 Jul 16 21:13 UTC

The regex will only affect timezones given in GMT, it won't affect say "UTC+08:00".

@golang golang locked and limited conversation to collaborators Jul 6, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.