Home

Published

- 1 min read

golang time difference in milliseconds

img of golang time difference in milliseconds

The solution for this is noted below

golang time difference in milliseconds

Solution

   package main
import (
        "log"
        "time"
)
func main() {
        start := time.Now().UnixNano() / int64(time.Millisecond)
        // do something
        time.Sleep(1 * time.Second)
        end := time.Now().UnixNano() / int64(time.Millisecond)
        diff := end - start
        log.Printf("Duration(ms): %d", diff)
}

Try other methods by searching on the site. That is if this doesn’t work