On Wed, May 5, 2021 at 2:04 PM Bagas Sanjaya <bagasdo...@gmail.com> wrote: > > I need to display date in "month year" format, for example "August 2018". > > So I had this minimal reproducible code (excluding package name and import > statements): > > ``` > func main() { > target := TargetDate(8) > > fmt.Println("Target month is ", target.Format("January 2009")) > } > > // TargetDate returns target date for selected month > func TargetDate(month int) time.Time { > return time.Date(2018, time.Month(month), 1, 0, 0, 0, 0, time.UTC) > } > ``` > > I expected that the output date for code above was "August 2018", > but what I got was "August 1009". But when I changed the date format string > to "January 2006" (year 2006 as on the reference time mentioned in > documentation for `time`), I got the expected result. > > Was above a bug?
You wrote 2009 where you need to write 2006. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXVvgSh9NRJUZjYdie9o%2BjpGtfe7%3D4NVAGw8s7oDyZbGA%40mail.gmail.com.