Time
Use time.Time
for instants of time
time.Time
for instants of timeUse time.Time
when dealing with instants of time, and the methods on time.Time
when comparing, adding, or subtracting time.
Use time.Duration
for periods of time
time.Duration
for periods of timeUse time.Duration
when dealing with periods of time.
Getting Next Day
Going back to the example of adding 24 hours to a time instant, the method we use to add time depends on intent. If we want the same time of the day, but on the next calendar day, we should use Time.AddDate
. However, if we want an instant of time guaranteed to be 24 hours after the previous time, we should use Time.Add
.
Last updated