Standard library / time

time.Duration.Truncate()

Round toward zero to a multiple of m; nonpositive m leaves d unchanged. Expected stdout: '-1s\n'.

Formal Syntax & Structure

go syntaxgo
func (d Duration) Truncate(m Duration) Duration

Parameters & Attributes

NameTypeDescription
mDurationRounding or truncation interval.

Return Value

Duration

Round toward zero to a multiple of m; nonpositive m leaves d unchanged.

Working Example

Example Snippetgo
package main
import (  "fmt"  "time")
func main() { fmt.Println((-1500 * time.Millisecond).Truncate(time.Second)) }
Go Reference