← All notes

Go time: measure and display clocks and durations

Answer: The time package measures and displays time. Its calendrical calculations assume a Gregorian calendar in all cases. Add adds the same duration to both the wall clock and monotonic clock readings. Sleep pauses the current goroutine.

Examples

package main
import "time"

func main() {
    now := time.Now()
    later := now.Add(2 * time.Second)
    time.Sleep(10 * time.Millisecond)
    _ = later.Sub(now)
}

Notes

The zero Time value does not format as a normal date. On some systems the clock can stop if the computer goes to sleep, and Sub may not accurately reflect the actual time that passed. Duration values such as Second are used with Add and Sleep.

Reference list

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go docs, time package; Go source, time.go. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go docs, time package; Go source, time.go. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.

Cite this

Permanent ID: iil:note:rmnpjpkk

iinventedlight. 2026. "Go time: measure and display clocks and durations." iinventedlight Library, iil:note:rmnpjpkk, version of 2026-11-18. https://iinventedlight.com/library/notes/go-time/. License: CC-BY-4.0.

@misc{iil_note_rmnpjpkk,
  author = {{iinventedlight}},
  title = {{Go time: measure and display clocks and durations}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/go-time/},
  note = {Permanent ID iil:note:rmnpjpkk. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-time.md.