Skip to content

Instantly share code, notes, and snippets.

@sthorne
Created June 3, 2016 19:43
Show Gist options
  • Save sthorne/c4facfe7db2130aae42223528c65d5c3 to your computer and use it in GitHub Desktop.
Save sthorne/c4facfe7db2130aae42223528c65d5c3 to your computer and use it in GitHub Desktop.
Validating Time in String
package main
import (
"fmt"
"time"
)
func main() {
Form := "3:04pm"
timesToCheck := []string{"7:54pm", "09:00pm", "09:00am", "08:55pm", "08:54am", "1:00pm", "23:00am"}
for _, v := range timesToCheck {
if t, e := time.Parse(Form, v); e != nil {
fmt.Println(e.Error())
} else {
fmt.Printf("%#v\n", t)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment