Skip to content

Instantly share code, notes, and snippets.

@tmc
Last active December 19, 2015 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmc/5937579 to your computer and use it in GitHub Desktop.
Save tmc/5937579 to your computer and use it in GitHub Desktop.
// parses arguments into a time duration and prints the number of seconds it represents
package main
import (
"fmt"
"os"
"strings"
"time"
)
func main() {
d, err := time.ParseDuration(strings.Join(os.Args[1:], ""))
if err != nil {
fmt.Fprintln(os.Stderr, "error parsing duration:", err)
os.Exit(1)
}
fmt.Println(d.Seconds())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment