The 2021 answer:
As of go v1.17, the time
package added UnixMicro()
and UnixMilli()
, so the correct answer would be: time.Now().UnixMilli()
Original answer:
Just divide it:
func makeTimestamp() int64 {
return time.Now().UnixNano() / int64(time.Millisecond)
}
Here is an example that you can compile and run to see the output
package main
import (
"time"
"fmt"
)
func main() {
a := makeTimestamp()
fmt.Printf("%d \n", a)
}
func makeTimestamp() int64 {
return time.Now().UnixNano() / int64(time.Millisecond)
}