0

Hi I am trying to parse date in the format YYYY-MM-DD. I am trying this:

time.Parse("2020-12-30", "2016-01-01")

but I get the error, which I guess is a parsing error,

0001-01-01 00:00:00 +0000 UTC parsing time "2016-01-01" as "2020-12-30": cannot parse "-01-01" as "0-"

How do I parse this, maybe give some hints through additional examples? TIA.

Deepak Saini
  • 2,810
  • 1
  • 19
  • 26

1 Answers1

2

time.Parse() uses a reference time of Mon Jan 2 15:04:05 -0700 MST 2006 as its format:

time.Parse("2006-01-02", "2016-01-01")

Playground example: https://play.golang.org/p/34XaXjHF7hy.

Brad Solomon
  • 38,521
  • 31
  • 149
  • 235