Created
April 26, 2024 02:47
-
-
Save misterunix/556f8f98fa8a6113729ab88d0c3692f6 to your computer and use it in GitHub Desktop.
I run some very long tasks and I like to know how long they ran.
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
// Convert seconds to days, hours, minutes and seconds | |
func Seconds2Weeks(s float64) string { | |
var result string | |
si := int(s) | |
weeks := si / (7 * 24 * 3600) // get weeks from seconds | |
si = si % (7 * 24 * 3600) | |
day := si / (24 * 3600) // get days from seconds | |
si = si % (24 * 3600) | |
hour := si / 3600 // get hours from remaining seconds | |
si %= 3600 | |
minutes := si / 60 // get minutes from remaining seconds | |
si %= 60 | |
result = fmt.Sprintf("%dw:%dd:%02dh:%02dm:%02ds", weeks, day, hour, minutes, si) | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment