sleep and elapsed time



examples/sleep/sleep.go
package main

import (
    "fmt"
    "time"
)

func main() {
    before := time.Now()
    fmt.Printf("%T\n", before)
    fmt.Println(before.UnixNano())

    time.Sleep(1000000) // 1 ms

    after := time.Now()
    fmt.Println(after.UnixNano())

    elapsed := after.Sub(before)
    fmt.Printf("Elapsed: %T  %v\n", elapsed, elapsed)
}

examples/sleep/sleep.out
time.Time
1587754553086396917
1587754553087857409
Elapsed: time.Duration  1.460494ms