-
Notifications
You must be signed in to change notification settings - Fork 23
Q: Time Format "unix" #170
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
Comments
Hi, thanks for question. It's outputting the Unix timestamp in seconds. How else would you expect it to represent sub-second precision if it were an integer? |
Note that if you round to the nearest second, then the sub-second fraction is missing, making it equivalent to a JSON integer. |
My expectation was, that I get only the seconds (as int). Basically the same as if I call https://pkg.go.dev/time#Time.Unix, or https://pkg.go.dev/time#Time.UnixMilli, ...
|
With the current semantics, you could accomplish what you expect by first calling |
Rounding every time before marshaling seems impractical. For what it's worth, with
I disagree. If one needs high precision there is high precision formats like Additionally there are the matching
|
I understand what you're saying, but there's a difference between the format (i.e., the representation of a timestamp as a number with the units of seconds) versus the precision, as those are somewhat orthogonal concerns. This is going beyond a question now and into the territory of a proposal where we can benefit from wider discussion. I recommend you file a proposal at https://github.com/golang/go/issues and tag golang/go#71497 as the parent issue. Thanks. |
I created the proposal golang/go#73486. |
Is it really intended, that the time format
unix
encodes a time.Time with nanoseconds as a float? I would have expected and int.The text was updated successfully, but these errors were encountered: