golang time.millisecond * int code example
Example 1: golang time format with milliseconds
package main
import (
"fmt"
"time"
)
func main() {
timeFormatMilisecondsWithTrailingZero()
timeFormatMilisecondsWithoutTrailingZero()
}
func timeFormatMilisecondsWithTrailingZero() {
fmt.Println(time.Now().Format("2006-01-02 15:04:05.000"))
}
func timeFormatMilisecondsWithoutTrailingZero() {
fmt.Println(time.Now().Format("2006-01-02 15:04:05.999"))
}
Example 2: time now golang int64
now := time.Now()
sec := now.Unix()
nsec := now.UnixNano()
fmt.Println(now)
fmt.Println(sec)
fmt.Println(nsec)