相关疑难解决方法(0)

按时间段的分数睡觉

有人能告诉我为什么这样有效:

s := time.Hour/73.0
fmt.Println("sleeping: ", s)
time.Sleep(s)
Run Code Online (Sandbox Code Playgroud)

但这失败了:

d := 73.0
s := time.Hour/d
fmt.Println("sleeping: ", s)
time.Sleep(s)
Run Code Online (Sandbox Code Playgroud)

这是错误:

invalid operation: time.Hour / d (mismatched types time.Duration and float64)
Run Code Online (Sandbox Code Playgroud)

time types const type-conversion go

1
推荐指数
1
解决办法
484
查看次数

标签 统计

const ×1

go ×1

time ×1

type-conversion ×1

types ×1