func toTime()

in pkg/sls-plugin.go [1083:1102]


func toTime(sTime string) (t time.Time) {
	if v, err := strconv.ParseFloat(sTime, 64); err == nil {
		if len(sTime) == 13 {
			t = time.Unix(int64(v)/1000, 0)
		} else {
			t = time.Unix(int64(v), 0)
		}
		return
	}
	re := regexp.MustCompile(`(\d{4})\S(\d{2})\S(\d{2})[\s\S](\d{2})\S(\d{2})\S(\d{2}).*`)
	matched := re.FindAllStringSubmatch(sTime, -1)
	if matched != nil {
		s := fmt.Sprintf("%s-%s-%s %s:%s:%s", matched[0][1], matched[0][2], matched[0][3],
			matched[0][4], matched[0][5], matched[0][6])

		local, _ := time.LoadLocation("Asia/Shanghai")
		t, _ = time.ParseInLocation("2006-01-02 15:04:05", s, local)
	}
	return
}