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

proposal: time: support Colon for fractional seconds #36145

trbroyles1 opened this issue Dec 15, 2019 · 5 comments

proposal: time: support Colon for fractional seconds #36145

trbroyles1 opened this issue Dec 15, 2019 · 5 comments


Copy link

@trbroyles1 trbroyles1 commented Dec 15, 2019

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

$ go version
go version go1.12.7 windows/amd64

Does this issue reproduce with the latest release?

Yes, I can reproduce it on the playground

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


go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\N555074\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\Development\go
set GOROOT=D:\Go
set GOTOOLDIR=D:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\N555074\AppData\Local\Temp\go-build289214998=/tmp/go-build -gno-record-gcc-switches

What did you do?

Attempt to parse a date/time string containing milliseconds preceded by a colon. Example:

What did you expect to see?

Time is 02/12/2019 15:45:48:746

What did you see instead?

parsing time "02/12/2019 15:45:48:746" as "02/01/2006 15:04:05:000": cannot parse "746" as ":000"
Copy link

@tannerryan tannerryan commented Dec 15, 2019

This is not an issue. Please review the documentation for package time:

A fractional second is represented by adding a period and zeros to the end of the seconds section of layout string, as in "15:04:05.000" to format a time stamp with millisecond precision.

For your example, the format string must be 02/01/2006 15:04:05.000, not 02/01/2006 15:04:05:000. The input string must also be corrected.

Here is your example corrected:

@robpike robpike closed this Dec 16, 2019
Copy link

@trbroyles1 trbroyles1 commented Dec 16, 2019

I'm sorry but I have to disagree. I reviewed the documentation thoroughly before writing the original issue, and I am well aware that the problem does not occur if a period is used in place of a colon. That was the whole point of the report I filed. The generated file I am processing uses a colon instead of a period. Which is non-standard, I completely agree. But, that's kind of my point. Non-standard things happen "in the wild", and the library needs to be able to handle them.

Yes, I can work around it by doing a search and replace on the colon in the string. That's what I'm doing for now. But the whole point of a format string, is to... specify the format of the string you want to parse. It's seems we've missed the mark if we have cases like that that it is impossible to format for.

Please, I would ask you, give the issue some more consideration before dropping it again. I'm not expecting this will change tomorrow or anything like that, but isn't it better in the long term if the format strings are able to cover a wider variety of cases ?

This general theme seems to be a recurring issue, to wit:

Couldn't some consideration be given to this? Alternatively, maybe this is a plus point for the priority of localization support

Copy link

@agnivade agnivade commented Dec 16, 2019

It seems like you want to file a proposal, rather than an issue. And from what I understand, your proposal is very similar to #6189. I'd suggest that you can subscribe to that issue for updates. Or if you feel the colon as a separator deserves its own proposal, please feel free to go ahead and file one.

@josharian josharian reopened this Dec 16, 2019
@josharian josharian changed the title time: Colon not supported in fractional seconds proposal: time: support Colon for fractional seconds Dec 16, 2019
@gopherbot gopherbot added this to the Proposal milestone Dec 16, 2019
@gopherbot gopherbot added the Proposal label Dec 16, 2019
Copy link

@josharian josharian commented Dec 16, 2019

All the details are here already—reopened and converted to proposal.

Copy link

@tengattack tengattack commented Jun 16, 2020

Maybe you can try this package: ;) for arbitrary format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.