How to Parse a Date String in Go

Parse a date string in Go using time.Parse with the 2006-01-02 reference layout.

Use time.Parse with a reference time string to convert a date string into a time.Time value. The reference string must match the layout exactly, using 2006-01-02 for year-month-day formats.

import "time"

layout := "2006-01-02"
value, err := time.Parse(layout, "2023-10-25")
if err != nil {
    panic(err)
}