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 two essential methods to operate on date and time.

The first method, Add, accepts the time.Duration and AddDate. With the Add method, you can shift the time toward the future with the positive sign and move the time backward just by adding the negative sign.

The second method, AddDate, consumes the int64 arguments as the year, month, and day, and adds the bigger time amounts.

Beware that AddDate normalizes the result, the same as the time.Date function. Normalization means that adding the month to Aug-31 will result in Oct-1, because the following month contains only 30 days (Sep-31 does not exist).

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