Date Arithmetic
examples/date-arithmetic/date_arithmetic.go
package main import ( "fmt" "time" ) func main() { t := time.Now() fmt.Printf("%T\n", t) fmt.Printf("Now: %v\n", t) d2 := t.AddDate(0, 0, 2) fmt.Printf("2 days from now: %v\n", d2) y1 := t.AddDate(1, 0, 0) fmt.Printf("A year from now: %v\n", y1) m1 := t.AddDate(0, -1, 0) fmt.Printf("Last month: %v\n", m1) fmt.Println() fmt.Printf("Now: %v\n", t) }
time.Time Now: 2020-04-24 22:20:50.306276218 +0300 IDT m=+0.000028191 2 days from now: 2020-04-26 22:20:50.306276218 +0300 IDT A year from now: 2021-04-24 22:20:50.306276218 +0300 IDT Last month: 2020-03-24 22:20:50.306276218 +0200 IST Now: 2020-04-24 22:20:50.306276218 +0300 IDT m=+0.000028191