字符串转为时间对象time.Time

5年以前  |  阅读数:619 次  |  编程语言:Golang 
const TIME_LAYOUT = "2006-01-02 15:04:05"

func parseWithLocation(name string, timeStr string) (time.Time, error) {
    locationName := name
    if l, err := time.LoadLocation(locationName); err != nil {
        println(err.Error())
        return time.Time{}, err
    } else {
        lt, _ := time.ParseInLocation(TIME_LAYOUT, timeStr, l)
        fmt.Println(locationName, lt)
        return lt, nil
    }
}

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8