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/recipe03.
  2. Navigate to the directory.
  3. Create the parse.go file with the following content:
        package main        import (          "fmt"          "time"        )        func main() {          // If timezone is not defined          // than Parse function returns          // the time in UTC timezone.          t, err := time.Parse("2/1/2006", "31/7/2015")          if err != nil {            panic(err)          }          fmt.Println(t)          // If timezone is given than it is parsed          // in given timezone          t, err = time.Parse("2/1/2006 3:04 PM MST",                               "31/7/2015 1:25 AM DST")          if err != nil {            panic(err)          }          fmt.Println(t)          // Note that the ParseInLocation          // parses the time in given location, if the          // string does not contain time zone definition          t, err = time.ParseInLocation("2/1/2006 3:04 PM ",  "31/7/2015 ...

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