In Go language, time packages supplies functionality for determining as well as viewing time. The Time.Sub() function in Go language is used to yield the duration obtained by performing the operation t-u. And if the output here surpasses the maximum or the minimum value that can be stored in a Duration “d” then the maximum or the minimum duration will be returned. Moreover, this function is defined under the time package. Here, you need to import “time” package in order to use these functions.
Syntax:func (t Time) Sub(u Time) Duration
Here, “t” and “u” are the stated time.
Note: In order to calculate “t-d” for a given duration “d” you need to use t.Add(-d).
Return value: It returns the duration obtained by performing the operation t-u.
t-d = 10462h45m16.000000036s
t-d = 10470h1m8.999999963s
Here, the times “t” and “u” stated in the above code have values that are out of usual range but they are normalized while conversion.