Golang time.Time.AddDate() function example

package time

Golang time.Time.AddDate() function usage example

 package main

 import (
 "fmt"
 "time"
 )

 func main() {

 now := time.Now()

 fmt.Println("Today : ", now.Format(time.ANSIC))

 addDates := now.AddDate(1, 0, 0)

 fmt.Println("After 1 year : ", addDates.Format(time.ANSIC))

 }

Sample output :

Today : Mon Aug 3 15:42:17 2015

After 1 year : Wed Aug 3 15:42:17 2016

Reference :

http://golang.org/pkg/time/#Time.AddDate

Advertisement