index
A common requirement in programs is getting the number of seconds, milliseconds, or nanoseconds since the [Unix epoch](http://en.wikipedia.org/wiki/Unix_time). Here's how to do it in Go.
package main
import (
	"fmt"
	"time"
)
func main() {
Use `time.Now` with `Unix` or `UnixNano` to get elapsed time since the Unix epoch in seconds or nanoseconds, respectively.
	now := time.Now()
	secs := now.Unix()
	nanos := now.UnixNano()
	fmt.Println(now)
Note that there is no `UnixMillis`, so to get the milliseconds since epoch you'll need to manually divide from nanoseconds.
	millis := nanos / 1000000
	fmt.Println(secs)
	fmt.Println(millis)
2020-10-21 16:54:31.842940388 +0000 UTC m=+0.000067188
1603299271
1603299271842
	fmt.Println(nanos)
2020-10-21 16:54:32.304220566 +0000 UTC m=+0.000102698
1603299272
1603299272304
1603299272304220566
You can also convert integer seconds or nanoseconds since the epoch into the corresponding `time`.
	fmt.Println(time.Unix(secs, 0))
2020-10-21 16:54:34.06693101 +0000 UTC m=+0.000051144
1603299274
1603299274066
1603299274066931010
2020-10-21 16:54:34 +0000 UTC
	fmt.Println(time.Unix(0, nanos))
2020-10-21 16:54:34.438204406 +0000 UTC m=+0.000072338
1603299274438
1603299274438204406
2020-10-21 16:54:34.438204406 +0000 UTC
}
2020-10-21 16:54:34.776561116 +0000 UTC m=+0.000108196
1603299274776
1603299274776561116
2020-10-21 16:54:34.776561116 +0000 UTC
index