GO語言"time"包中"Duration.Round"類型的用法及代碼示例。
用法:
func(d Duration) Round(m Duration) Duration
Round 返回將 d 舍入為 m 的最接近倍數的結果。中間值的舍入行為是從零舍入。如果結果超過 Duration 中可以存儲的最大(或最小值)值,Round 返回最大(或最小)持續時間。如果 m <= 0,Round 返回 d 不變。
例子:
package main
import (
"fmt"
"time"
)
func main() {
d, err := time.ParseDuration("1h15m30.918273645s")
if err != nil {
panic(err)
}
round := []time.Duration{
time.Nanosecond,
time.Microsecond,
time.Millisecond,
time.Second,
2 * time.Second,
time.Minute,
10 * time.Minute,
time.Hour,
}
for _, r := range round {
fmt.Printf("d.Round(%6s) = %s\n", r, d.Round(r).String())
}
}
輸出:
d.Round( 1ns) = 1h15m30.918273645s d.Round( 1µs) = 1h15m30.918274s d.Round( 1ms) = 1h15m30.918s d.Round( 1s) = 1h15m31s d.Round( 2s) = 1h15m30s d.Round( 1m0s) = 1h16m0s d.Round( 10m0s) = 1h20m0s d.Round(1h0m0s) = 1h0m0s
相關用法
- GO Duration.Hours用法及代碼示例
- GO Duration.Truncate用法及代碼示例
- GO Duration.String用法及代碼示例
- GO Duration.Minutes用法及代碼示例
- GO Duration.Milliseconds用法及代碼示例
- GO Duration.Seconds用法及代碼示例
- GO Duration.Microseconds用法及代碼示例
- GO Duration.Nanoseconds用法及代碼示例
- GO Duration用法及代碼示例
- GO DumpResponse用法及代碼示例
- GO DumpRequest用法及代碼示例
- GO DumpRequestOut用法及代碼示例
- GO Dumper用法及代碼示例
- GO Dump用法及代碼示例
- GO DecodeLastRuneInString用法及代碼示例
- GO DB.QueryRowContext用法及代碼示例
- GO Date用法及代碼示例
- GO DB.ExecContext用法及代碼示例
- GO Dial用法及代碼示例
- GO DB.BeginTx用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 Duration.Round。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。