Add Duration to Time in Go

Posted by yhuang
Public (Editable by Users)
Go
Edit
package main

import (
    "fmt"
    "time"
)

func main() {
    p := fmt.Println

    now := time.Now()

    then := time.Date(
        2009, 11, 17, 20, 34, 58, 651387237, time.UTC)

    diff := now.Sub(then)

    p(then.Add(diff))
    p(then.Add(-diff))
}