Skip to content

Instantly share code, notes, and snippets.

@dantheman213
Created August 3, 2022 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dantheman213/0863814c63c80b7b7f21f26f01ad5adf to your computer and use it in GitHub Desktop.
Save dantheman213/0863814c63c80b7b7f21f26f01ad5adf to your computer and use it in GitHub Desktop.
Golang get time diff from a, b, formatted pretty
// 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