Golang : Convert seconds to minutes and remainder seconds
Problem:
You have an input seconds in integer that you want to convert into minutes and remainder seconds. How to do that?
Solution:
The secondsToMinutes()
function below will first get the minutes from the given input seconds and then calculate the remainder seconds.
Here you go!
package main
import (
"fmt"
)
func secondsToMinutes(inSeconds int) string {
minutes := inSeconds / 60
seconds := inSeconds % 60
str := fmt.Sprintf("d:d", minutes, seconds)
return str
}
func main() {
fmt.Println("3600 seconds in minutes : ", secondsToMinutes(3600))
fmt.Println("9999 seconds in minutes : ", secondsToMinutes(9999))
fmt.Println("660 seconds in minutes : ", secondsToMinutes(660))
fmt.Println("1234567890 seconds in minutes : ", secondsToMinutes(1234567890))
}
Output:
3600 seconds in minutes : 60:00
9999 seconds in minutes : 166:39
660 seconds in minutes : 11:00
1234567890 seconds in minutes : 20576131:30
See also : Golang : Convert date or time stamp from string to time.Time type
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8.9k Golang : Temperatures conversion example
+7.7k Golang : Tell color name with OpenCV example
+6.4k Golang : How to solve "too many .rsrc sections" error?
+11.6k Golang : flag provided but not defined error
+6.3k Golang : Warp text string by number of characters or runes example
+18.5k Golang : Check whether a network interface is up on your machine
+30.3k Golang : Calculate percentage change of two values
+4.9k JavaScript/JQuery : Redirect page examples
+11.2k Golang : Handle API query by curl with Gorilla Queries example
+5.5k PHP : Get client IP address
+28.5k Golang : Saving(serializing) and reading file with GOB
+6.8k Golang : How to fix html/template : "somefile" is undefined error?