Skip to content
Home » How to demonstrate the hours() function in Golang

How to demonstrate the hours() function in Golang

Learn about How to demonstrate the hours() function in Golang in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

How to demonstrate the hours() function in Golang

// Golang program to demonstrate the hours() function

package main

import "fmt"
import "time"

func main() {
	hours, _ := time.ParseDuration("20h30m20s")
	fmt.Printf("Total hours are: %.3f", hours.Hours())
}

In the above program, we declare the package main. We imported the fmt package, which contains the files of the fmt package, and then we can use a function related to the fmt package. Here, we created hours variable initialized using time.ParseDuration() function. Then get total hours in floating point format using Hours() function. The Hours() function returns float64 value.

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
How to demonstrate the Minutes() function in Golang
How to demonstrate the Nanoseconds() function in Golang