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
+6.1k Golang : Extract unicode string from another unicode string example
+14.4k Golang : Convert IP version 6 address to integer or decimal number
+7.2k Web : How to see your website from different countries?
+14.1k Golang : How to check if a file is hidden?
+19.6k Golang : How to count the number of repeated characters in a string?
+14k Golang : Convert spaces to tabs and back to spaces example
+8.9k Golang : How to join strings?
+19.7k Golang : Example for DSA(Digital Signature Algorithm) package functions
+12.4k Golang : Find and draw contours with OpenCV example
+14.6k Golang : Parsing or breaking down URL
+7.6k Golang : Process json data with Jason package
+16.1k Golang : Get digits from integer before and after given position example