Go version

go version go1.22.4 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/deke/Library/Caches/go-build'
GOENV='/Users/deke/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/deke/.gvm/pkgsets/go1.22.4/global/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/deke/.gvm/pkgsets/go1.22.4/global'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/deke/.gvm/gos/go1.22.4'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/deke/.gvm/gos/go1.22.4/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.22.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/kx/hbhfkyvn3d903_g_1hwrx3h80000gn/T/go-build236193593=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Parsing a time string with a "Z" time zone using a time format that includes time zone seconds fails.

https://go.dev/play/p/FgeEzRinnL8

What did you see happen?

The call to time.Parse returned an error. For example, this code:

tm, err = time.Parse("2006-01-02T15:04:05Z070000", "2024-07-01T12:34:56Z")
fmt.Println(tm)
fmt.Println(err)

outputs:

0001-01-01 00:00:00 +0000 UTC
parsing time "2024-07-01T12:34:56Z" as "2006-01-02T15:04:05Z070000": cannot parse "Z" as "Z070000"

What did you expect to see?

The call to time.Parse to succeed and return a time with the UTC time zone location. For example, this code:

tm, err = time.Parse("2006-01-02T15:04:05Z070000", "2024-07-01T12:34:56Z")
fmt.Println(tm)
fmt.Println(err)

SHOULD output:

2024-07-01 12:34:56 +0000 UTC
<nil>

Comment From: gabyhelp

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: gopherbot

Change https://go.dev/cl/595897 mentions this issue: time: fix time zone parsing when format includes time zone seconds

Comment From: thanm

HI @darinkrauss , have you looked at https://github.com/golang/go/issues/56528#issuecomment-1301168906 ? Seems related to me. Thanks.

Comment From: darinkrauss

Hi @thanm! I had not seen that comment. After reviewing, though, I'm not sure I see how it is related. This issue is related to parsing the ISO-8601 "Z" abbreviation for UTC when using the "Z070000" and "Z07:00:00" time formats. Parsing currently works for the other "Z"-related time formats (without seconds) such as "Z0700" and "Z07:00". What am I missing?