mirror of
https://gitee.com/johng/gf.git
synced 2024-12-01 11:48:09 +08:00
修复gtime时间解析问题
This commit is contained in:
parent
1608a96d98
commit
9fedea009d
@ -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 {
|
||||
|
@ -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))
|
||||
}
|
Loading…
Reference in New Issue
Block a user