Standard library / time
time.Time.Sub()
Return t minus u as a duration, saturating at representable limits. Use monotonic readings when both are present. Expected stdout: '1h30m0s\n'.
Formal Syntax & Structure
go syntaxgo
func (t Time) Sub(u Time) DurationParameters & Attributes
| Name | Type | Description |
|---|---|---|
| u | Time | Other instant for comparison or subtraction. |
Return Value
Duration
Return t minus u as a duration, saturating at representable limits.
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() { t := fixed(); fmt.Println(t.Add(90 * time.Minute).Sub(t)) }