Here, we are going to learn about how to convert time duration into minutes in Go. We will learn it by example and program.
Minutes() method of time package will be used to convert time duration into minutes in Go.
Function prototype:
func (d Duration) Minutes() float64
Input parameters:
Duration: type Duration int64
Return value:
Minutes() function in time package returns the duration as a floating point number of minutes.
Example with code:
package main
import (
"fmt"
"time"
)
func main() {
h, _ := time.ParseDuration("2h30m")
fmt.Printf("Convert 2 hour 30 minutes to Minutes: %.2f\n", h.Minutes())
h, _ = time.ParseDuration("2s")
fmt.Printf("Convert 2 seconds to Minutes: %.2f\n", h.Minutes())
h, _ = time.ParseDuration("30m")
fmt.Printf("Convert 30 minutes to Minutes: %.2f\n", h.Minutes())
}
Output:
Convert 2 hour 30 minutes to Minutes: 150.00
Convert 2 seconds to Minutes: 0.03
Convert 30 minutes to Minutes: 30.00
To learn more about golang, Please refer given below link:
https://techieindoor.com/go-lang-tutorial/
References:
https://golang.org/doc/
https://golang.org/pkg/