Parsing date/time strings which are not 'standard' formats

后端 未结 3 938
感动是毒
感动是毒 2020-11-28 02:57

How do I parse non-standard date/time strings in Go. In example if I wanted to convert the string 10/15/1983 into a time.Time? The time.Parse

3条回答
  •  春和景丽
    2020-11-28 03:37

    If you can't remember the Numbers in the specifying layout ("2006-01-02T15:04:05.000Z"), you may use my simple date formatting library github.com/metakeule/fmtdate that uses MS Excel conventions, like Y,M,D,h and internally translates them to the number format:

    package main
    
    import (
        "github.com/metakeule/fmtdate"
    
        "fmt"
    )
    
    func main() {
        test, err := fmtdate.Parse("MM/DD/YYYY", "10/15/1983")
        if err != nil {
            panic(err)
        }
    
        fmt.Println(test)
    }
    

提交回复
热议问题