Golang time.Time.Add() function example

package time

Golang time.Time.Add() function usage example

 package main

 import (
  "fmt"
  "time"
 )

 func main() {

  now := time.Now()

  fmt.Println("Today : ", now.Format("Mon, Jan 2, 2006 at 3:04pm"))

  fiveDays := time.Hour * 24 * 5

  diff := now.Add(fiveDays)

  fmt.Println("Five days from now will be : ", diff.Format(time.ANSIC))

 }

Output :

Today : Mon, Aug 3, 2015 at 3:36pm

Five days from now will be : Sat Aug 8 15:36:43 2015

Reference :

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

Advertisement