time.ParseDuration() Function in Golang With Examples Last Updated : 02 Apr, 2020 Comments Improve Suggest changes Like Article Like Report Go language provides inbuilt support for measuring and displaying time with the help of the time package. In this package, the calendrical calculations always assume a Gregorian calendar with no leap seconds. This package provides a ParseDuration() function which parses a duration string. Duration string is a signed sequence of decimal numbers with optional fraction and unit suffix, like "100ms", "2.3h" or "4h35m". To access ParseDuration() function you need to add a time package in your program with the help of the import keyword. Note: Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". Syntax: func ParseDuration(str string) (Duration, error) Example 1: C // Golang program to illustrate // how to find time duration package main import ( "fmt" "time" ) func main() { // Using ParseDuration() function hr, _ := time.ParseDuration("3h") comp, _ := time.ParseDuration("5h30m40s") fmt.Println("Time Duration 1: ", hr) fmt.Println("Time Duration 2: ", comp) } Output: Time Duration 1: 3h0m0s Time Duration 2: 5h30m40s Example 2: C // Golang program to illustrate // how to find time duration package main import ( "fmt" "time" ) func main() { // Using ParseDuration() function hr, _ := time.ParseDuration("5h") comp, _ := time.ParseDuration("2h30m40s") m1, _ := time.ParseDuration("3µs") m2, _ := time.ParseDuration("3us") fmt.Println("Time Duration 1: ", hr) fmt.Println("Time Duration 2: ", comp) fmt.Printf("There are %.0f seconds in %v.\n", comp.Seconds(), comp) fmt.Printf("There are %d nanoseconds in %v.\n", m1.Nanoseconds(), m1) fmt.Printf("There are %6.2e seconds in %v.\n", m2.Seconds(), m1) } Output: Time Duration 1: 5h0m0s Time Duration 2: 2h30m40s There are 9040 seconds in 2h30m40s. There are 3000 nanoseconds in 3µs. There are 3.00e-06 seconds in 3µs. Comment More infoAdvertise with us Next Article time.ParseDuration() Function in Golang With Examples K Kirti_Mangal Follow Improve Article Tags : Go Language GoLang-time Similar Reads time.Parse() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Parse() function in Go language is used to parse a formatted string and then finds the time value that it forms. Moreover, this function is defined under the time package. Here, you need to import "time 2 min read time.String() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The String() function in Go language is used to find a string that represents the duration formats as "24h6m0.7s". Here, the foremost zero units are deleted. And the stated duration with less than one-secon 2 min read time.Seconds() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Seconds() function in Go language is used to find the duration of time in the form of a floating-point number of seconds. Moreover, this function is defined under the time package. Here, you need to imp 2 min read time.Since() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Since() function in Go language holds time value and is used to evaluate the difference with the actual time. Moreover, this function is defined under the time package. Here, you need to import the "tim 2 min read time.Time.Sub() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Time.Sub() function in Go language is used to yield the duration obtained by performing the operation t-u. And if the output here surpasses the maximum or the minimum value that can be stored in a Durat 2 min read time.Round() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Round() function in Go language is used to find the outcome of rounding the stated duration 'd' to the closest multiple of 'm' duration. Here, the rounding manner for middle values is to round far off f 2 min read time.ParseError.Error() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The ParseError.Error() function in Go language is used to output the string description of a ParseError. Moreover, this function is defined under the time package. Here, you need to import "time" package in 2 min read time.Nanoseconds() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Nanoseconds() function in Go language is used to find the duration of time in form of an integer nanosecond count. Moreover, this function is defined under the time package. Here, you need to import the 2 min read time.Time.Second() Function in Golang with Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Time.Second() function in Go language is used to find the second offset within the minute as provided by "t" and the range is [0, 59]. Moreover, this function is defined under the time package. Here, yo 2 min read time.Time.IsZero() Function in Golang With Examples In Go language, time packages supplies functionality for determining as well as viewing time. The Time.IsZero() function in Go language is used to check if the stated time "t" implies zero time instant or not i.e, January 1, year 1, 00:00:00 UTC. Moreover, this function is defined under the time pac 2 min read Like