Golang time.Duration type example
package time
Golang time.Duration type usage example. These constants are useful in calculating time lapsed, total time, etc. Instead of declaring them, just use from time package. For example, day := 24*time.Hour
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println("Nano second : ", time.Nanosecond)
fmt.Println("Micro second : ", time.Microsecond)
fmt.Println("Milli second : ", time.Millisecond)
fmt.Println("Minute : ", time.Minute)
fmt.Println("Hour : ", time.Hour)
fmt.Println("Day : ", 24*time.Hour)
}
Output :
Nano second : 1ns
Micro second : 1µs
Milli second : 1ms
Minute : 1m0s
Hour : 1h0m0s
Day : 24h0m0s
See also :
Reference :
Advertisement
Something interesting
Tutorials
+12.5k Golang : Forwarding a local port to a remote server example
+10.9k Nginx : TLS 1.2 support
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+10.6k Golang : Resolve domain name to IP4 and IP6 addresses.
+5.8k Golang : Find change in a combination of coins example
+55.3k Golang : Unmarshal JSON from http response
+25.7k Golang : How to write CSV data to file
+9.9k Golang : Check if user agent is a robot or crawler example
+15.9k Golang : Get current time from the Internet time server(ntp) example
+6.7k Golang : When to use make or new?
+7.3k Golang : How to fix html/template : "somefile" is undefined error?