enhance(types):修正日期时间解析尝试模板。
This commit is contained in:
parent
686890b5d8
commit
5d938da53e
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
var dateLayouts = []string{
|
||||
"2006-01-02", "2006-1-2", "2006/01/02", "6-1-2", "6-01-02", "01/02/06", "1/2/6", "2006年01月02日", "06年1月2日",
|
||||
"2006-01-02", "2006-1-2", "2006/01/02", "06-1-2", "6-01-02", "01/02/06", "1/2/06", "2006年01月02日", "06年1月2日",
|
||||
}
|
||||
|
||||
type Date struct {
|
||||
|
|
|
@ -13,7 +13,8 @@ import (
|
|||
var (
|
||||
loc *time.Location = time.FixedZone("+0800", 8*60*60)
|
||||
datetimeLayouts = []string{
|
||||
"2006-01-02 15:04:05", "2006-1-2 15:04:05", "2006/01/02 15:04:05", "6-1-2 15:04:05", "6-01-02 15:04:05", "01/02/06 15:04:05", "1/2/6 15:04:05", "2006年01月02日 15:04:05", "06年1月2日 15:04:05",
|
||||
"2006-01-02 15:04:05", "2006-1-2 15:04:05", "2006/01/02 15:04:05", "06-1-2 15:04:05", "06-01-02 15:04:05", "01/02/06 15:04:05", "1/2/06 15:04:05", "2006年01月02日 15:04:05", "06年1月2日 15:04:05",
|
||||
"2006-01-02 15:04", "2006-1-2 15:04", "2006/01/02 15:04", "06-1-2 15:04", "06-01-02 15:04", "01/02/06 15:04", "1/2/06 15:04", "2006年01月02日 15:04", "06年1月2日 15:04",
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -49,6 +50,7 @@ func ParseDateTime(t string) (DateTime, error) {
|
|||
return NewEmptyDateTime(), fmt.Errorf("不能解析空白的日期时间。")
|
||||
}
|
||||
for _, layout := range datetimeLayouts {
|
||||
fmt.Printf("Parse: %s, Try layout: %s\n", t, layout)
|
||||
d, err := time.ParseInLocation(layout, t, loc)
|
||||
if err == nil {
|
||||
return DateTime{
|
||||
|
|
Loading…
Reference in New Issue
Block a user