In Go language, time packages supplies functionality for determining as well as viewing time. The Time.AddDate() function in Go language is used to check the time which is equivalent to adding the stated number of years, months, and days to the given “t”.
For example, if the parameters of the method are like (-2, 4, 5) and the stated t is February 3, 2018 then the output will be June 8, 2016. Like Date method here also if the range of months, days or years are outside the normal range then its automatically converted to normalized range. Moreover, this function is defined under the time package. Here, you need to import “time” package in order to use these functions.
func (t Time) AddDate(years int, months int, days int) Time
Here, “t” is the stated time.
Return Value: It returns the result of adding stated t to the stated number of years, months, and days.
2018-06-04 00:00:00 +0000 UTC 2019-08-09 00:00:00 +0000 UTC 2023-04-13 00:00:00 +0000 UTC 2018-09-01 00:00:00 +0000 UTC 2019-06-04 00:00:00 +0000 UTC
Here, the output returned is in UTC as defined above.
2021-04-03 00:00:00 +0000 UTC 2025-06-07 00:00:00 +0000 UTC 2021-05-02 00:00:00 +0000 UTC 2027-11-02 00:00:00 +0000 UTC 2027-01-23 00:00:00 +0000 UTC
Here, the range used is outside the usual range but they are normalized while converted.