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) DurationParameters & Attributes
| Name | Type | Description |
|---|---|---|
| m | Duration | Rounding 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)) }