Skip to content

time.Parse fails at parsing time.String #17253

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

Closed
Yndoendo opened this issue Sep 27, 2016 · 1 comment
Closed

time.Parse fails at parsing time.String #17253

Yndoendo opened this issue Sep 27, 2016 · 1 comment

Comments

@Yndoendo
Copy link

Yndoendo commented Sep 27, 2016

time.Parse can not parse the default format produced by time.String()

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

go1.7.1 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="$HOME/.local/share/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build766838131=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

What did you do?

https://play.golang.org/p/wmfQP5wX0S

func main() {
    t := time.Now().UTC()
    s := t.String()

    t, err := time.Parse(s,s)
    if err != nil {
        fmt.Println(s, "parsed with error", err)
    } else {
        fmt.Println(s, "equals", t.String())
    }
}

What did you expect to see?

2016-09-27 16:53:03.13465009 +0000 UTC equals 2016-09-27 16:53:03.13465009 +0000 UTC

What did you see instead?

There were different out comes, local:

2016-09-27 16:53:03.13465009 +0000 UTC parsed with error parsing time "2016-09-27 16:53:03.13465009 +0000 UTC": month out of range

go playground:

2009-11-10 23:00:00 +0000 UTC parsed with error parsing time "2009-11-10 23:00:00 +0000 UTC" as "2009-07-10 23:00:00 +0000 UTC": cannot parse "9-11-10 23:00:00 +0000 UTC" as "009"
@bradfitz
Copy link
Contributor

Not a bug. The result of String is not a valid format.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants