Posted on 9th May 2025|80 views
How can I get the difference between two time objects?
In my code, I have two time.Time objects and I want to calculate their difference here are the two terms
t1 = 2017-09-08 20:09:18 +0520 IST
t2 = 2017-09-08 20:09:18 +0520 IST
In this case, the difference would be 00:00:00, but this is not showing the result in that format why?
Posted on 9th May 2025| views
So if you want the result in the time format like HH:mm:ss you just have to construct a time.Time value and utilize its Time.Format() like this
out := time.Time{}.Add(diff)
fmt.Println(out.Format("15:04:05"))
This will give you the result as you desire.