Obtaining the current date is a very common task for any system or application. Let's look at how this is done with help of Go's standard library.
Finding today's date
How to do it...
- Open the console and create the folder chapter04/recipe01.
- Navigate to the directory.
- Create the today.go file with the following content:
package main
import (
"fmt"
"time"
)
func main() {
today := time.Now()
fmt.Println(today)
}
- Execute the code by running go run today.go in the main Terminal.
- You will see the following output: