time package | Golang time Format
ADurationrepresentstheelapsedtimebetweentwoinstantsasanint64nanosecondcount.Therepresentationlimitsthelargestrepresentabledurationtoapproximately290years.packagemainimport("fmt""time")funcexpensiveCall(){}funcmain(){t0:=time.Now()expensiveCall()t1:=time.Now()fmt.Printf("Thecalltook%vtorun.",t1.Sub(t0))}Output:ParseDurationparsesadurationstring.Adurationstringisapossiblysignedsequenceofdecimalnumbers,eachwithoptionalfractionandaunitsuffix,suchas"300ms","-1.5h"or"2h45m".Validtimeunitsare"ns","...
A Duration represents the elapsed time between two instants as an int64 nanosecond count. The representation limits the largest representable duration to approximately 290 years.
package main import ( "fmt" "time" ) func expensiveCall() {} func main() { t0 := time.Now() expensiveCall() t1 := time.Now() fmt.Printf("The call took %v to run. ", t1.Sub(t0)) } Output:ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
package main import ( "fmt" "time" ) func main() { hours, _ := time.ParseDuration("10h") complex, _ := time.ParseDuration("1h10m10s") micro, _ := time.ParseDuration("1µs") // The package also accepts the incorrect but common prefix u for micro. micro2, _ := time.ParseDu...