Standard library / log/slog

slog.Time()

Construct a keyed Time attribute for structured logging. Expected stdout: 'key\n1970-01-01 00:00:00 +0000 UTC\n'.

Formal Syntax & Structure

go syntaxgo
func Time(key string, v time.Time) Attr

Parameters & Attributes

NameTypeDescription
keystringAttribute key.
vtime.TimeValues to log or convert.

Return Value

Attr

Construct a keyed Time attribute for structured logging.

Working Example

Example Snippetgo
package main
import (  "fmt"  "log/slog"  "time")
func main() { a := slog.Time("key", time.Unix(0, 0).UTC()); fmt.Println(a.Key); fmt.Println(a.Value) }
Go Reference