Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Date.Format is outputting very strange dates

I have a Date.Time var that is:

2022-03-28 00:00:00 +0000 UTC

when i do:

Date.Time.Format("2003-12-22")

I get something like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

1999-131-311

Looking to just have it be formatted to YYYY-MM-DD

>Solution :

"2006-01-02 15:04:05 -0700 MST", "2006-01-02" are layout to convert your date.

Code:

originalDate, err := time.Parse("2006-01-02 15:04:05 -0700 MST", "2022-03-28 00:00:00 +0000 UTC")
if err != nil {
    fmt.Println(err)
    return
}

formattedDate := originalDate.Format("2006-01-02")
fmt.Println(formattedDate)

Output:

2022-03-28
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading