The source code to demonstrate the hours() function is given below. The given program is compiled and executed successfully.
// 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())
}
Output:
Total hours are: 20.506
Explanation:
In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt and time packages to use time and fmt related functions.
In the main() function, 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.
After that, we printed the result on the console screen.
Program/Source Code:
The source code to demonstrate the hours() function is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt and time packages to use time and fmt related functions.
In the main() function, 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.
After that, we printed the result on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer