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

Convert nano time to string return garbage? #39089

proyb6 opened this issue May 15, 2020 · 1 comment

Convert nano time to string return garbage? #39089

proyb6 opened this issue May 15, 2020 · 1 comment


Copy link

@proyb6 proyb6 commented May 15, 2020

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


Does this issue reproduce with the latest release?

I think earlier may have the same issue, I have checked other repos have used the same approach.

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


What did you do?

Converting nano time to string


What did you expect to see?

As expected number return by nano time.

What did you see instead?

A question mark character

Copy link

@acln0 acln0 commented May 15, 2020

string(x) doesn't do what you think it does when x is an integer. It interprets x as a unicode code point and creates a string with the UTF-8 encoding of said code point, if possible. For your particular case, it isn't possible, so you get an encoding of unicode.ReplacementChar instead:

To format an integer into a string, use the fmt or strconv package.

@proyb6 proyb6 closed this May 15, 2020
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
2 participants
You can’t perform that action at this time.