I see you can use a cool date format with Hugo using natural language, but I can’t figure out how to simply return the YYYY-MM-DD format from the front matter.
When calling using {{ .Date }} I get:
2014-11-25 00:00:00 +0000 UTC
When calling using {{ .Date.Format "YYYY-MM-DD" }} I get:
MMMM-YY-DD
“…To expand upon @DerekPerkins response; Go uses a model date for formatting, or layout…”
But why? That is the question.
I got caught out by this too, thinking I could just use an appropriate example for whichever part of the date I wanted. When i put in “2014” as the year format, I got some crazy date about 40000 years into the future.
By picking a default date, there is less parsing that needs to happen, plus they chose a date that shows definitively how to handle things like leading zeroes, day/month ordering and other edge cases that aren’t discernible from all dates.
It’s weird coming from other languages that have you send in formatting strings like “YYYY-MM-DD”, but Go has never concerned itself with doing it the same way as everyone else just because.
I can see where the Go syntax makes it easier in some ways. I’m forever forgetting some of the more obscure formatting settings in other languages that [for example] distinguish between 12/24 hour time or [as you said] include/exclude leading zeroes, etc.
I’m not convinced this solves the problem though. Now, with Go, instead of remembering those obscure switches, I’ve got to remember a complete and [to me] arbitrary date and time instead. And, given the amount of rolling pin dents I have on my head owing to forgetting the missus’s birthday, I don’t think it’s going to prove any easier.
BTW –I did not realise this date formula was a ‘Go’ thing, I thought it was a quirk of Hugo. So thanks for clearing that up, anyway.
Hey this is great however I think I encountered a bug when using certain format strings. I am not entire sure why this bug is happening.
Ah nevermind. It turns out I wasn’t using the correct string formatting. For example ‘_2’ = day of the month, 05 is always the seconds and 06 is always the year.