Standard library / time

time.Date()

Construct a calendar time in loc; out-of-range fields normalize, nil loc panics, and ambiguous DST times are not uniquely resolved. Expected stdout: '2024-03-01\n'.

Formal Syntax & Structure

go syntaxgo
func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time

Parameters & Attributes

NameTypeDescription
yearintCalendar year.
monthMonthCalendar month.
dayintDay of month; out-of-range values normalize.
hourintHour component.
minintMinute component.
secintSecond component.
nsecintNanosecond component.
loc*LocationLocation providing calendar and zone rules.

Return Value

Time

Construct a calendar time in loc; out-of-range fields normalize, nil loc panics, and ambiguous DST times are not uniquely resolved.

Working Example

Example Snippetgo
package main
import (  "fmt"  "time")
func main() { fmt.Println(time.Date(2024, 2, 30, 0, 0, 0, 0, time.UTC).Format(time.DateOnly)) }
Go Reference