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 Sub method of the Time instance is the universal one to find out the difference between two dates. The result is time.Duration, which represents the nanosecond count between these dates.

Note that if the difference exceeds the limit of the maximum/minimum time.Duration, then the maximum or minimum is returned.

The functions Since and Until are just a shorter way on how to work out the difference between now and the given date. These work as their names prompts. The Since function returns the same result as time.Now().Sub(t); similarly, the Until returns the same result as t.Sub(time.Now()).

The Sub method naturally also counts with time zones. So, the difference is returned with respect to the location of each Time instance. ...

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