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) Time

Parameters & Attributes

NameTypeDescription
yearsintSigned calendar years to add.
monthsintSigned calendar months to add.
daysintSigned 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))}
Go Reference