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/recipe02.
  2. Navigate to the directory.
  3. Create the format.go file with the following content:
        package main        import (          "fmt"          "time"        )        func main() {          tTime := time.Date(2017, time.March, 5, 8, 5, 2, 0, time.Local)          // The formatting is done          // with use of reference value          // Jan 2 15:04:05 2006 MST          fmt.Printf("tTime is: %s\n", tTime.Format("2006/1/2"))          fmt.Printf("The time is: %s\n", tTime.Format("15:04"))          //The predefined formats could          // be used          fmt.Printf("The time is: %s\n", tTime.Format(time.RFC1123))          // The formatting supports space padding          //only for days in Go version 1.9.2          fmt.Printf("tTime is: %s\n", tTime.Format("2006/1/_2"))          // The zero padding is done by adding 0 fmt.Printf("tTime ...

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