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.


I’ve been working on a cli tool in Go when I ran into this issue. The tool compiles and works perfectly fine when I use the Windows Command Prompt or PowerShell to run it but when I try using WSL (Ubuntu version 1) I get this error message.

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

The file using time.Now().UnixMilli() has the package time included import(..."time"...) and it is not redefined elsewhere because the code compiles and runs correctly in the Windows terminals. Because of this I assume that it has something to do with Linux for Windows.

I have tried updating the $GOROOT and $GOPATH to various different places including trying to connect to go installed on the mounted Windows system /mnt/c/ (this gives a different error of not knowing how compile which makes sense since it’s the Windows version of go). I have also tried uninstalling and reinstalling various versions of Go for Ubuntu using both apt-get and tar.

I’m not sure why it isn’t working correctly and would love any insight that anyone else might have.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.