Created
July 24, 2013 16:39
-
-
Save chespinoza/6072236 to your computer and use it in GitHub Desktop.
io2str in action in order to parse a datetime (Ignoring microsecs)
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 ( | |
"bufio" | |
"fmt" | |
"strings" | |
"time" | |
) | |
const TLAYOUT = "01/02/2006 15:04:05" | |
func main() { | |
str := []byte("T=06/06/2013 23:49:06.000\r\n") | |
reader := bufio.NewReader(strings.NewReader(string(str))) | |
line, _ := reader.ReadString('\n') | |
if line[:1] == "T" { | |
t, err := time.Parse(TLAYOUT, line[2:21]) | |
if err != nil { | |
fmt.Println(line[2:21]) | |
fmt.Println(err) | |
} else { | |
fmt.Println(t) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment