#How to use a time.Parse in golang?

7 messages · Page 1 of 1 (latest)

dense pasture
#
    dateStr := "July 25, 2019 13:45:00"
    layout := "January 2, 2006 00:00:00"
    
    parsedTime, err := time.Parse(layout, dateStr)
    if err != nil {
        fmt.Println("Error parsing date:", err)
        return
    }

    fmt.Println("Parsed Time:", parsedTime)

I'm getting error in this snippet. How do you use time.Parse()?

lavish fiber
#

Is this for an Exercism exercise?

I'd check your layout vs. Go's reference date and time and see if you may have missed something in your layout.

lunar rune
#

They were directed here by @warm whale so at this point, it is not required that it be an exercise on Exercism (as we usually require).

That said, @dense pasture it is definitely good to show your error, as directed, and to expand on what you expected to happen and how that is different than what happened.

Without this information, it is going to be hard to help you.

grand geyser
#

This looks like the Booking with Beauty exercise, I think?

dense pasture
#

@lunar rune @lavish fiber @grand geyser I figured it out. I had to match the layout to the exact date and time as specified in the go documentation.

grand geyser
#

🎉

#

Sounds about right