package main import ( "fmt" "time" ) func main() { t := time.Date(2021, time.October, 10, 0, 0, 0, 0, time.UTC) tFuture := t.AddDate(0, 1, 0) // add one month fmt.Println(tFuture) }
package main import ( "fmt" "time" ) func main() { t := time.Now() tPast := t.AddDate(0, -6, 0) // subtract six months fmt.Println(tPast) }In this example, we use the AddDate method to subtract six months from the current time instance. The output will be a new Time instance set to six months ago from the current time. These examples demonstrate the usefulness of the AddDate method in manipulating Time instances. The package library used is the time package.