package main import ( "fmt" "time" ) func main() { durationInSeconds := time.Duration(5) * time.Second fmt.Println(durationInSeconds) }
package main import ( "fmt" "time" ) func main() { durationInSeconds := time.Duration(5) * time.Second newDurationInSeconds := durationInSeconds + (time.Duration(10) * time.Second) fmt.Println(newDurationInSeconds) }
package main import ( "fmt" "time" ) func main() { durationInSeconds := time.Duration(3700) * time.Second hours := int(durationInSeconds.Hours()) minutes := int(durationInSeconds.Minutes()) % 60 seconds := int(durationInSeconds.Seconds()) % 60 fmt.Printf("%02d:%02d:%02d", hours, minutes, seconds) }In the above example, the duration of time is given in seconds (3700 seconds), the code converts this duration to hours, minutes, and seconds format using the Hours(), Minutes(), and Seconds() methods provided by the package. Package library: time.