Understand the contract

time.Time represents an instant, while time.Duration represents an elapsed interval as a nanosecond count. Use named units such as time.Second to make intervals readable. Parse timestamps with a known layout, keep timezone information and format explicitly when producing text for another system.

Go layouts use a reference date rather than tokens such as YYYY. time.RFC3339 supplies a standard layout for timestamps with an offset. time.Parse returns an error for mismatching input. UTC normalizes display to a common offset while preserving the instant represented by the value.

Work through the example

The example parses noon at offset -06:00, adds ninety minutes and prints the result in UTC. Multiplying 90 by time.Minute states the unit. For measuring actual work, time.Now followed by time.Since is preferable to manually subtracting wall-clock strings.

package main

import (
    "fmt"
    "time"
)

func main() {
    start, err := time.Parse(time.RFC3339, "2026-11-01T12:00:00-06:00")
    if err != nil { fmt.Println(err); return }
    end := start.Add(90 * time.Minute)
    fmt.Println(end.UTC().Format(time.RFC3339))
}

Watch this boundary

A fixed offset is not a geographical timezone with historical daylight-saving rules. Use time.LoadLocation when those rules matter and handle its error. Also, time.Duration(5) means five nanoseconds, not five seconds. Keep units visible in configuration parsing and tests.

Practice with a changed input

Parse the same instant with a Z suffix and compare it using Equal. Then parse "250ms" with time.ParseDuration and reject an invalid duration string.

References & further reading

Need help with your Go backend?

I work with engineering teams on focused Go and Kubernetes platform engagements, with limited consulting availability.

Explore Go consulting services