Standard library / time

time.Time.Before()

Report whether t is strictly earlier than u; equality returns false. Expected stdout: 'true false\n'.

Formal Syntax & Structure

go syntaxgo
func (t Time) Before(u Time) bool

Parameters & Attributes

NameTypeDescription
uTimeOther instant for comparison or subtraction.

Return Value

bool

Report whether t is strictly earlier than u; equality returns false.

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.Before(t.Add(time.Second)), t.Before(t)) }
Go Reference