Created
August 3, 2022 20:26
-
-
Save dantheman213/0863814c63c80b7b7f21f26f01ad5adf to your computer and use it in GitHub Desktop.
Golang get time diff from a, b, formatted pretty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// e.g. returns 00:00:25 | |
func getTimeDiff(a, b time.Time) string { | |
d := b.Sub(a) | |
hour := int(d.Seconds() / 3600) | |
minute := int(d.Seconds() / 60) % 60 | |
second := int(d.Seconds()) % 60 | |
return fmt.Sprintf("%02d:%02d:%02d", hour, minute, second) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment