Golang program to demonstrate the Seconds() function

Here, we are going to demonstrate the Seconds() function in Golang (Go Language).
Submitted by Nidhi, on March 23, 2021

Problem Solution:

In this program, we will demonstrate the Seconds() function to get the total seconds in floating-point format by specifying time in a specific format.

Program/Source Code:

The source code to demonstrate the Seconds() function is given below. The given program is compiled and executed successfully.

// Golang program to demonstrate the
// Seconds() function

package main

import "fmt"
import "time"

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


Total Seconds are: 12750.000000


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 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.

Golang Date & Time Programs »



Comments and Discussions!





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.