The Time type also provides the API to retrieve time units from the instance. This means you are able to find out what day in a month or what hour in a day the instance represents. This recipe shows how to obtain such units.
Retrieving time units from the date
How to do it...
- Open the console and create the folder chapter04/recipe05.
- Navigate to the directory.
- Create the units.go file with the following content:
package main
import (
"fmt"
"time"
)
func main() {
t := time.Date(2017, 11, 29, 21, 0, 0, 0, time.Local)
fmt.Printf("Extracting units from: %v\n", t)
dOfMonth := t.Day()
weekDay := t.Weekday()
...