我想计算一个睡觉的时间,但我被卡住了。我可以睡10秒钟:
time.Sleep(10 * time.Second)
但是,我尝试以下方法:
package main
import (
"log"
"time"
"reflect"
)
func main() {
n := time.Now()
remaining := 10 - int(time.Since(n).Seconds())
log.Println(reflect.TypeOf(10), reflect.TypeOf(remaining))
//time.Sleep(10 * time.Second)
time.Sleep(remaining * time.Second)
}
我明白了:
invalid operation: remaining * time.Second (mismatched types int and time.Duration)
剩下的是一个int,就像10是一个int。是什么给了什么?