Skip to content

Instantly share code, notes, and snippets.

@chespinoza
Created July 24, 2013 16:39
Show Gist options
  • Save chespinoza/6072236 to your computer and use it in GitHub Desktop.
Save chespinoza/6072236 to your computer and use it in GitHub Desktop.
io2str in action in order to parse a datetime (Ignoring microsecs)
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