Created
June 3, 2016 19:43
-
-
Save sthorne/c4facfe7db2130aae42223528c65d5c3 to your computer and use it in GitHub Desktop.
Validating Time in String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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