go duration比较
作者:互联网
func Test() {
var waitFiveHundredMillisections time.Duration = 500 * time.Millisecond
startingTime := time.Now().UTC()
time.Sleep(600 * time.Millisecond)
endingTime := time.Now().UTC()
var duration time.Duration = endingTime.Sub(startingTime)
if duration >= waitFiveHundredMillisections {
fmt.Printf("Wait %v\nNative [%v]\nMilliseconds [%d]\nSeconds [%.3f]\n", waitFiveHundredMillisections, duration, duration.Nanoseconds()/1e6, duration.Seconds())
}
}
得到的输出如下:
Wait 500ms
Native [601.091066ms]
Milliseconds [601]
Seconds [0.601]
标签:Millisecond,endingTime,duration,startingTime,time,go,waitFiveHundredMillisection 来源: https://blog.csdn.net/qq_32907195/article/details/120731947