Obtaining a Unix Timestamp in Go Language (current time in seconds since epoch)

crc picture crc · Mar 2, 2012 · Viewed 90.2k times · Source

I have some code written in Go which I am trying to update to work with the latest weekly builds. (It was last built under r60). Everything is now working except for the following bit:

 if t, _, err := os.Time(); err == nil {
   port[5] = int32(t)
 }

Any advice on how to update this to work with the current Go implementation?

Answer

user811773 picture user811773 · Mar 2, 2012
import "time"
...
port[5] = int32(time.Now().Unix())