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

How to demonstrate the Seconds() function in Golang

Learn about How to demonstrate the Seconds() 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 Seconds() function in Golang

// Golang program to demonstrate the Seconds() function

package main

import "fmt"
import "time"

func main() {
	t, _ := time.ParseDuration("5h45m25s")
	fmt.Printf("Total Seconds are: %f", t.Seconds())
}

Here we created t variable initialized using time.ParseDuration() function. Then get total seconds in the floating-point format using the Seconds() function. The Seconds() function returns float64 value. After that, we printed the result on the console screen.

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 print date and time according to the specified location in Golang
How to print all months using predefined constants in Golang