August 2019
Beginner to intermediate
798 pages
17h 2m
English
The name of the Go program that will be developed in this subsection is parseDate.go and it will be presented in two parts.
The first part of parseDate.go is next:
package main
import (
"fmt"
"os"
"path/filepath"
"time"
)
func main() {
var myDate string
if len(os.Args) != 2 {
fmt.Printf("usage: %s string\n", filepath.Base(os.Args[0]))
return
}
myDate = os.Args[1]
The second part of parseDate.go contains the following Go code:
d, err := time.Parse("02 January 2006", myDate)
if err == nil {
fmt.Println("Full:", d)
fmt.Println("Time:", d.Day(), d.Month(), d.Year())
} else {
fmt.Println(err)
}
}
If there is a character such as - between the name of the month and the year, you can use "02 January-2006" instead of "02 January ...
Read now
Unlock full access