-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd.go
58 lines (54 loc) · 1.2 KB
/
d.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
package d
import "time"
func Date(params ...interface{}) string {
// 定义默认值
defaultValues := map[int]interface{}{
0: "Y-m-d H:i:s", // format
1: 0, // date
2: "UTC+8", // date
}
defaultCount := len(defaultValues)
count := len(params)
value := defaultCount - count
if value > 0 {
for i := defaultCount - value; i < defaultCount; i++ {
params = append(params, defaultValues[i])
}
}
format := params[0]
day := params[1].(int)
result := "format error"
currentDateTime := time.Unix(time.Now().Unix()+int64(86400*day), 0)
switch format {
case "Y-m-d H:i:s":
result = currentDateTime.Format("2006-01-02 15:04:05")
break
case "Y-m-d":
result = currentDateTime.Format("2006-01-02")
break
case "H:i:s":
result = currentDateTime.Format("15:04:05")
break
case "Y":
result = currentDateTime.Format("2006")
break
case "m":
result = currentDateTime.Format("01")
break
case "d":
result = currentDateTime.Format("02")
break
case "H":
result = currentDateTime.Format("15")
break
case "i":
result = currentDateTime.Format("04")
break
case "s":
result = currentDateTime.Format("05")
break
default:
result = "format error"
}
return result
}