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

Strange time.Parse() behavior. #18798

Closed
morriswinkler-simple opened this issue Jan 26, 2017 · 4 comments
Closed

Strange time.Parse() behavior. #18798

morriswinkler-simple opened this issue Jan 26, 2017 · 4 comments

Comments

@morriswinkler-simple
Copy link

██ go version
go version go1.7.4 darwin/amd64

██ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/morris/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/tk/kxjq9h991j70hc37wvrzx10m0000gn/T/go-build886718705=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

package main

import (
	"fmt"
	"time"
)


const(
	dateFormatMhhh = `2017-01-19 18:24:40.423 CET`
	dateFormat = `2006-01-19 18:24:40.000 CET`
)


func main() {



	entryCreatedDate := time.Now().Format(dateFormatMhhh)
	fmt.Println(entryCreatedDate)
	entryCreatedDate = time.Now().Format(dateFormat)
	fmt.Println(entryCreatedDate)
}

What did you expect to see?

2017-01-19 18:269:90.926 CET
2017-01-19 18:269:90.927 CET

What did you see instead?

26017-01-19 18:269:90.9262 CET
2017-01-19 18:269:90.927 CET
@morriswinkler-simple morriswinkler-simple changed the title Strange time. Strange time.Parse() behavior. Jan 26, 2017
@Ganners
Copy link

Ganners commented Jan 26, 2017

Your date format must correspond to Mon Jan 2 15:04:05 MST 2006 (https://golang.org/pkg/time/#pkg-constants)

Therefore you want your date format to probably be: 2006-01-02 15:04:05.000 MST

Your received output was therefore correct. I think your expectations are also incorrect

@morriswinkler-simple
Copy link
Author

morriswinkler-simple commented Jan 26, 2017

Makes sense, but how would you read that from the docs?

Format returns a textual representation of the time value formatted according   
to layout, which defines the format by showing how the reference time,    
defined to be

Mon Jan 2 15:04:05 -0700 MST 2006

This is not that clear.

@cznic
Copy link
Contributor

cznic commented Jan 26, 2017

This is not that clear.

Seems reasonably clear to me. Do you want to suggest a clarification?

@ianlancetaylor
Copy link
Member

This has already been clarified further in Go 1.8; see https://tip.golang.org/pkg/time/#Time.Format .

@golang golang locked and limited conversation to collaborators Jan 26, 2018
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

5 participants