tn.UnixMilli undefined (type time.Time has no field or method UnixMilli)

I got this issue in circle ci after pushing to github (see image below).

Go version : 1.15

Is there a way of solving this issue without upgrading Go to at least version 1.17

No. The time.Time.UnixMilli method wasn’t added until Go 1.17, so you cannot use it in Go 1.15. You could change your code to call time.Time.UnixNano which does exist in Go 1.15 and then divide the answer by 1,000,000.

1 Like

It seems that function is available from Go 1.16 and above…

1 Like

@MIMOMODE - Curious, why are you stuck with Go 1.15?

1 Like

Thanks for all your answers, my boss wants me to upgrade go to version 1.19. is it hard (i never worked with go before) like should i just change the version on docker and rebuild the project on the server ?

By the way, i’m using the function time.Now() , the probleme is probably from there.

It should be easier than with other languages.

The Go1 compatibility promise says that all Go source code, no matter how old, basically should work with the newest Go 1.x toolchain.

It is intended that programs written to the Go 1 specification will continue to compile and run correctly, unchanged, over the lifetime of that specification.

There are, however, notable exceptions. For example, a security fix might break this backwards compatibility because security ranks higher.
I recommend reading the article and study the full list of exceptions and the OS- and toolchain-specific limitations.

In any case, thorough testing is advisable. But I daresay the risk and depth of problems arising from upgrading the Go toolchain is much smaller than with other languages that do not put that much efforts into staying backwards compatible.

1 Like

thanks, so basically it would not be problematique. i tried to upgrade to go 1.17 but this error appeared :

The error message indicates that there is no go.mod file in that directory.

If the project does not use Go Modules, it might be time to start using them. The toolchain relies more and more on projects to use modules. This blog series can get you started.

2 Likes