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 it works...

The Time type of the time package provides the Format method for formatting the output string.

Go uses the referential time value Jan 2 15:04:05 2006 MST to define the formatting layout. See the code example for padding options.

The memo for the reference date is that when given in number form, it is represented as 1,2,3,4,5,6,-7. The -7 value means that the MST time zone is 7 hours behind the UTC.

The time package includes some predefined formats (for example, time.Kitchen); you can discover these in the documentation for package constants. (https://golang.org/pkg/time/#pkg-constants)

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