-
Notifications
You must be signed in to change notification settings - Fork 7
/
GoDateFormat.go
106 lines (92 loc) · 3.05 KB
/
GoDateFormat.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package GoDateFormat
import (
"strings"
)
const (
yyyy = "2006"
yy = "06"
mmmm = "January"
mmm = "Jan"
mm = "01"
dddd = "Monday"
ddd = "Mon"
dd = "02"
HHT = "03"
HH = "15"
MM = "04"
SS = "05"
ss = "05"
tt = "PM"
Z = "MST"
ZZZ = "MST"
o = "Z07:00"
)
func ConvertFormat(format string) (string){
var goFormate = format;
if strings.Contains(goFormate, "YYYY") {
goFormate = strings.Replace(goFormate, "YYYY", yyyy, -1)
} else if strings.Contains(goFormate, "yyyy") {
goFormate = strings.Replace(goFormate, "yyyy", yyyy, -1)
} else if strings.Contains(goFormate, "YY") {
goFormate = strings.Replace(goFormate, "YY", yy, -1)
} else if strings.Contains(goFormate, "yy") {
goFormate = strings.Replace(goFormate, "yy", yy, -1)
}
if strings.Contains(goFormate, "MMMM") {
goFormate = strings.Replace(goFormate, "MMMM", mmmm, -1)
} else if strings.Contains(goFormate, "mmmm") {
goFormate = strings.Replace(goFormate, "mmmm", mmmm, -1)
} else if strings.Contains(goFormate, "MMM") {
goFormate = strings.Replace(goFormate, "MMM", mmm, -1)
} else if strings.Contains(goFormate, "mmm") {
goFormate = strings.Replace(goFormate, "mmm", mmm, -1)
} else if strings.Contains(goFormate, "mm") {
goFormate = strings.Replace(goFormate, "mm", mm, -1)
}
if strings.Contains(goFormate, "dddd") {
goFormate = strings.Replace(goFormate, "dddd", dddd, -1)
} else if strings.Contains(goFormate, "ddd") {
goFormate = strings.Replace(goFormate, "ddd", ddd, -1)
} else if strings.Contains(goFormate, "dd") {
goFormate = strings.Replace(goFormate, "dd", dd, -1)
}
if strings.Contains(goFormate, "tt"){
if strings.Contains(goFormate, "HH") {
goFormate = strings.Replace(goFormate, "HH", HHT, -1)
} else if strings.Contains(goFormate, "hh") {
goFormate = strings.Replace(goFormate, "hh", HHT, -1)
}
goFormate = strings.Replace(goFormate, "tt", tt, -1)
} else {
if strings.Contains(goFormate, "HH") {
goFormate = strings.Replace(goFormate, "HH", HH, -1)
} else if strings.Contains(goFormate, "hh") {
goFormate = strings.Replace(goFormate, "hh", HH, -1)
}
goFormate = strings.Replace(goFormate, "tt", "", -1)
}
if strings.Contains(goFormate, "MM"){
goFormate = strings.Replace(goFormate, "MM", MM, -1)
}
if strings.Contains(goFormate, "SS") {
goFormate = strings.Replace(goFormate, "SS", SS, -1)
} else if strings.Contains(goFormate, "ss"){
goFormate = strings.Replace(goFormate, "ss", SS, -1)
}
if strings.Contains(goFormate, "ZZZ"){
goFormate = strings.Replace(goFormate, "ZZZ", ZZZ, -1)
} else if strings.Contains(goFormate, "zzz"){
goFormate = strings.Replace(goFormate, "zzz", ZZZ, -1)
} else if strings.Contains(goFormate, "Z"){
goFormate = strings.Replace(goFormate, "Z", Z, -1)
} else if strings.Contains(goFormate, "z"){
goFormate = strings.Replace(goFormate, "z", Z, -1)
}
if strings.Contains(goFormate, "tt"){
goFormate = strings.Replace(goFormate, "tt", tt, -1)
}
if strings.Contains(goFormate, "o"){
goFormate = strings.Replace(goFormate, "o", o, -1)
}
return (goFormate)
}