Standard library / time

time.Time.Add()

Return the instant d later, preserving a monotonic reading when representable. It adds elapsed time, not calendar days. Expected stdout: '14:34:56\n'.

Formal Syntax & Structure

go syntaxgo
func (t Time) Add(d Duration) Time

Parameters & Attributes

NameTypeDescription
dDurationElapsed duration or interval.

Return Value

Time

Return the instant d later, preserving a monotonic reading when representable.

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(2 * time.Hour).Format(time.TimeOnly)) }
Go Reference
time.Time.Add() — Go Syntax & Examples | ByteMind