Standard library / flag
flag.Duration()
Registers a flag on the default command line. Duration parsed using time.ParseDuration; include a unit such as ms or s. Run with arguments: ["-x=250ms"]. Expected stdout: '250ms\n'.
Formal Syntax & Structure
go syntaxgo
func Duration(name string, value time.Duration, usage string) *time.DurationParameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | Name of the flag or flag set. |
| value | time.Duration | Default value for registration, or text to parse for Set. |
| usage | string | Help text describing the flag. |
Return Value
*time.Duration
Registers a flag on the default command line.
Working Example
Example Snippetgo
package main
import ( "flag" "fmt" "time")
func main() { v := flag.Duration("x", time.Second, "value"); flag.Parse(); fmt.Println(*v) }