August 2019
Beginner to intermediate
798 pages
17h 2m
English
This section will tell you how to parse a string, which is given as a command-line argument to the parseTime.go utility in order to convert it into a time variable. However, this is not always possible because the given string might not be in the correct format or might contain invalid characters. The parseTime.go utility will be presented in three parts.
The first code segment of parseTime.go is next:
package main
import (
"fmt"
"os"
"path/filepath"
"time"
)
The second part comes with the next code:
func main() {
var myTime string
if len(os.Args) != 2 {
fmt.Printf("usage: %s string\n", filepath.Base(os.Args[0]))
os.Exit(1)
}
myTime = os.Args[1]
The last portion of parseTime.go, which is where the magic happens, is the following: ...
Read now
Unlock full access