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.UnixNow() & time.UnixNowMs() #39837
Comments
I suggest that you use https://pkg.go.dev/golang.org/x/sys/unix?tab=doc#Gettimeofday which calls the |
Also if you're fine with using unsafe, you can do something like: package main
import (
"fmt"
"time"
_ "unsafe"
)
//go:linkname timeNow runtime.walltime
func timeNow() (sec int64, nsec int32)
func main() {
fmt.Println(timeNow())
t := time.Now()
fmt.Println(t.Unix(), t.Nanosecond())
} |
@ianlancetaylor I'm getting 0 result from that, I think it's because of this issue: #38925 @OneOfOne thanks, seems like it's working! anything I should be careful with the unsafe usage? |
I'm using:
Just to check, it returns the unix timestamp, right? Not the "time of day" (e.g. seconds since start of day) |
Yes, |
Hi, in our code we call time.Now() pretty extensively, enough to notice some overhead of calling it. Since we only need the unix timestamp, can we have a way to just get the unix timestamp without allocating unnecessary Time{} structs?
The text was updated successfully, but these errors were encountered: