-
Notifications
You must be signed in to change notification settings - Fork 3
/
date.go
37 lines (31 loc) · 782 Bytes
/
date.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package emlparser
import (
"time"
)
var dateFormats = []string{
`Mon, 02 Jan 2006 15:04 -0700`,
`02 Jan 2006 15:04 -0700`,
`Mon, 02 Jan 2006 15:04:05 -0700`,
`02 Jan 2006 15:04:05 -0700`,
`Mon, 02 Jan 2006 15:04 -0700 (MST)`,
`02 Jan 2006 15:04 -0700 (MST)`,
`Mon, 02 Jan 2006 15:04:05 -0700 (MST)`,
`02 Jan 2006 15:04:05 -0700 (MST)`,
`Mon, 2 Jan 2006 15:04 -0700`,
`2 Jan 2006 15:04 -0700`,
`Mon, 2 Jan 2006 15:04:05 -0700`,
`2 Jan 2006 15:04:05 -0700`,
`Mon, 2 Jan 2006 15:04 -0700 (MST)`,
`2 Jan 2006 15:04 -0700 (MST)`,
`Mon, 2 Jan 2006 15:04:05 -0700 (MST)`,
`2 Jan 2006 15:04:05 -0700 (MST)`,
}
func ParseDate(s string) time.Time {
for _, fmt := range dateFormats {
t, e := time.Parse(fmt, s)
if e == nil {
return t
}
}
return time.Now()
}