time

Core
import "time"

Provides functionality for measuring and displaying time, durations, timers, and tickers.

Example

package main

import (
    "fmt"
    "time"
)

func main() {
    now := time.Now()
    fmt.Println(now.Format("2006-01-02 15:04:05"))
    time.Sleep(1 * time.Second)
    fmt.Println(time.Since(now))
}

Key Types & Functions

TimeDurationNowSinceSleepAfterTickerTimerParseFormat

About time

The time package (imported as time) belongs to the Core category of Go packages. Provides functionality for measuring and displaying time, durations, timers, and tickers.

Go's standard library is one of the language's greatest strengths, providing production-ready implementations for networking, cryptography, encoding, I/O, and more. The time package follows Go's philosophy of simplicity and composability — small, focused packages that combine through interfaces like io.Reader and io.Writer.

When using time in production, follow Go best practices: handle errors explicitly, use context for cancellation and timeouts, prefer composition over inheritance, and write table-driven tests. The Go documentation at pkg.go.dev provides comprehensive API references and examples for every exported type and function.

Related Packages