O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Open the console and create the folder chapter04/recipe07.
  2. Navigate to the directory.
  3. Create the diff.go file with the following content:
        package main        import (          "fmt"          "time"        )        func main() {          l, err := time.LoadLocation("Europe/Vienna")          if err != nil {            panic(err)          }          t := time.Date(2000, 1, 1, 0, 0, 0, 0, l)          t2 := time.Date(2000, 1, 3, 0, 0, 0, 0, l)          fmt.Printf("First Default date is %v\n", t)          fmt.Printf("Second Default date is %v\n", t2)          dur := t2.Sub(t)          fmt.Printf("The duration between t and t2 is %v\n", dur)          dur = time.Since(t)          fmt.Printf("The duration between now and t is %v\n", dur)          dur = time.Until(t)          fmt.Printf("The duration between t and now is %v\n", dur)        }
  1. Execute the code by running go run diff.go in the main Terminal. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required