Standard library / time
time.Time.AddDate()
Add calendar years, months and days in the current location. Normalizes dates and may span 23 or 25 hours across DST; it strips monotonic readings. Expected stdout: '2024-03-02\n'.
Formal Syntax & Structure
go syntaxgo
func (t Time) AddDate(years int, months int, days int) TimeParameters & Attributes
| Name | Type | Description |
|---|---|---|
| years | int | Signed calendar years to add. |
| months | int | Signed calendar months to add. |
| days | int | Signed calendar days to add. |
Return Value
Time
Add calendar years, months and days in the current location.
Working Example
Example Snippetgo
package main
import ( "fmt" "time")
func main() { t := time.Date(2024, 1, 31, 0, 0, 0, 0, time.UTC) fmt.Println(t.AddDate(0, 1, 0).Format(time.DateOnly))}