Standard library / time
time.Time.Truncate()
Round down to a multiple of d since the zero time, not local midnight. Nonpositive d strips monotonic data without rounding. Expected stdout: '12:34:00\n'.
Formal Syntax & Structure
go syntaxgo
func (t Time) Truncate(d Duration) TimeParameters & Attributes
| Name | Type | Description |
|---|---|---|
| d | Duration | Elapsed duration or interval. |
Return Value
Time
Round down to a multiple of d since the zero time, not local midnight.
Working Example
Example Snippetgo
package main
import ( "fmt" "time")
func fixed() time.Time { return time.Date(2024, 2, 29, 12, 34, 56, 123000000, time.UTC) }func main() { fmt.Println(fixed().Truncate(time.Minute).Format(time.TimeOnly)) }