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) TimeParameters & Attributes
| Name | Type | Description |
|---|---|---|
| year | int | Calendar year. |
| month | Month | Calendar month. |
| day | int | Day of month; out-of-range values normalize. |
| hour | int | Hour component. |
| min | int | Minute component. |
| sec | int | Second component. |
| nsec | int | Nanosecond component. |
| loc | *Location | Location 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)) }