diff --git a/g/os/gtime/gtime.go b/g/os/gtime/gtime.go index 3263b53da..29dbfb0ff 100644 --- a/g/os/gtime/gtime.go +++ b/g/os/gtime/gtime.go @@ -156,7 +156,7 @@ func StrToTime(str string, format...string) (*Time, error) { } var year, month, day int var hour, min, sec, nsec int - var array, match []string + var match []string var local = time.Local if match = timeRegex1.FindStringSubmatch(str); len(match) > 0 { for k, v := range match { @@ -179,12 +179,8 @@ func StrToTime(str string, format...string) (*Time, error) { s += strings.Repeat("0", 6 - len(s)) } hour, _ = strconv.Atoi(s[0 : 2]) - if len(array) >= 2 { - min, _ = strconv.Atoi(s[2 : 4]) - } - if len(array) >= 3 { - sec, _ = strconv.Atoi(s[4 : 6]) - } + min, _ = strconv.Atoi(s[2 : 4]) + sec, _ = strconv.Atoi(s[4 : 6]) } // 纳秒,检查并执行位补齐 if len(match[3]) > 0 { diff --git a/geg/other/test.go b/geg/other/test.go index 6319394aa..469d4028c 100644 --- a/geg/other/test.go +++ b/geg/other/test.go @@ -2,15 +2,13 @@ package main import ( "fmt" - "gitee.com/johng/gf/g/util/gutil" + "gitee.com/johng/gf/g/os/gtime" ) func main() { - gutil.TryCatch(func() { - fmt.Println(1) - panic("error") - fmt.Println(2) - }, func(err interface{}) { - fmt.Println(err) - }) + s := ` +172.20.1.198 - - [2018-11-06T16:26:09+08:00] "POST /passport HTTP/1.1" "OK" 1 200 0.000 0.035 0.035 0.035 448 "-" "-" "-" "{\x22jsonrpc\x22:\x222.0\x22,\x22method\x22:\x22getSessionInfo\x22,\x22params\x22:[\x2262703819__6augmxzV9f5c7o4MEimnMqPhoyKWPi8pXjs2VIj3T43vBfuGZOJ9DxrbRNsFB0ew\x22,true,{\x22platform\x22:\x22web-ph\x22}],\x22id\x22:1}" http unix:/var/run/php/php5.6-fpm.sock med3-svr [med3-svr-65494945bf-jppth] "" "" "" [med3-svr-65494945bf-jppth] +` + + fmt.Println(gtime.ParseTimeFromContent(s)) } \ No newline at end of file