Standard library / time
time.Duration.Round()
Round to nearest multiple of m, ties away from zero; nonpositive m returns d unchanged. Saturates if result overflows. Expected stdout: '-2s\n'.
Formal Syntax & Structure
go syntaxgo
func (d Duration) Round(m Duration) DurationParameters & Attributes
| Name | Type | Description |
|---|---|---|
| m | Duration | Rounding or truncation interval. |
Return Value
Duration
Round to nearest multiple of m, ties away from zero; nonpositive m returns d unchanged.
Working Example
Example Snippetgo
package main
import ( "fmt" "time")
func main() { fmt.Println((-1500 * time.Millisecond).Round(time.Second)) }