I was asked to look into Golang 1.20 to present the changes, not expecting to find much after the huge release of Go 1.18.
Aside from some exciting changes, I’ve also learned about many features that I wasn’t aware of before reading the release notes meticulously.
In order to actually show that these changes provide value, I will present issues and show how the new features solve these issues.
Issue 1: I want to format the date or time in a string form And it’s a hassle and error-prone.
I am going to write how to print out the current date:
now := time.Now()
formatted := now.Format("2007-01-02")
fmt.Println(formatted)
This will print out:
21007-03-21
????????
If you are sharp and read the code you can see I made a mistake.
The format is incorrect and should be: “2006–01–02" instead of “2007–01–02”.
Now, I never remember dates and always look it up and the cost of a mistake is huge.