The Go [time](<https://golang.org/pkg/time/>)
package provides functionality for handling time and date.
Major types in the package:
time.Time
represents time and date valuestime.Duration
represents difference between two time.Time
values in nanosecondstime.Second
, time.Millisecond
etc. are constants of time.Duration
that are easier to use than nanosecondsnow := time.Now()
t := time.Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time
loc
must be provided and represents time zone. Use time.UTC
variable for UTC time zone.
areEqual := t1.Equal(t2)
newTime := now.Add(5 * time.Second + time.Millisecond * 100)
Time values are immutable. Add
returns a new value.
newTime := now.Add(-6 * time.Second)
To subtract 6 seconds we add -6 seconds.
Adding a duration is for durations smaller than 24 hours.