Getting a Unix Timestamp in Go: Current Time in Seconds Since Epoch
In earlier versions of Go, such as r60, obtaining a Unix timestamp (the current time in seconds since the epoch) could be achieved with code like this:
if t, _, err := os.Time(); err == nil { port[5] = int32(t) }
However, with newer weekly builds, this approach is outdated. To update the code for current Go implementations:
Here's the updated code:
import "time" // ... port[5] = time.Now().Unix()
This code will now correctly obtain the current Unix timestamp, ensuring compatibility with the latest Go builds.
The above is the detailed content of How Do I Get a Unix Timestamp in Go?. For more information, please follow other related articles on the PHP Chinese website!