VptPassiveAdapter/util/parse_date.go
2025-02-07 22:58:01 +08:00

17 lines
387 B
Go

package util
import (
"fmt"
"regexp"
"time"
)
func ParseDate(filePath string) (time.Time, error) {
re := regexp.MustCompile(`(\d{4}).?(\d{2}).?(\d{2})`)
matches := re.FindStringSubmatch(filePath)
if len(matches) != 4 {
return time.Time{}, fmt.Errorf("无法解析时间范围")
}
return time.Parse("2006.01.02", fmt.Sprintf("%s.%s.%s", matches[1], matches[2], matches[3]))
}