forked from duolabmeng6/goefun
/
时间操作.go
153 lines (141 loc) · 3.74 KB
/
时间操作.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package E
import (
"github.com/gogf/gf/os/gtime"
)
//A simple extension for Time based on PHP's Carbon library. https://github.com/uniplaces/carbon
//到时间
//增减时间
//取时间间隔
//取某月天数
//时间到文本
//取时间部分
//取年份-
//取月份-
//取日-
//取星期几
//取小时
//取分钟
//取秒
//指定时间
//取现行时间
//置现行时间
//取日期
//取时间
type E日期时间型 struct {
Time *gtime.Time
}
func (this *E日期时间型) E取星期几() int64 {
return E到整数(this.Time.Format("N"))
}
func (this *E日期时间型) E取月天数() int64 {
return E到整数(this.Time.Format("t"))
}
func (this *E日期时间型) E取年份() int64 {
return E到整数(this.Time.Format("Y"))
}
func (this *E日期时间型) E取月份() int64 {
return E到整数(this.Time.Format("m"))
}
func (this *E日期时间型) E取日() int64 {
return E到整数(this.Time.Format("d"))
}
func (this *E日期时间型) E取小时() int64 {
return E到整数(this.Time.Format("H"))
}
func (this *E日期时间型) E取分钟() int64 {
return E到整数(this.Time.Format("i"))
}
func (this *E日期时间型) E取秒() int64 {
return E到整数(this.Time.Format("s"))
}
func (this *E日期时间型) E取毫秒() int64 {
return E到整数(this.Time.Millisecond())
}
func (this *E日期时间型) E取微秒() int64 {
return E到整数(this.Time.Microsecond())
}
func (this *E日期时间型) E取纳秒() int64 {
return E到整数(this.Time.Nanosecond())
}
func (this *E日期时间型) E取时间戳() int64 {
return this.Time.Timestamp()
}
func (this *E日期时间型) E取时间戳毫秒() int64 {
return this.Time.TimestampMilli()
}
func (this *E日期时间型) E取时间戳微秒() int64 {
return this.Time.TimestampMicro()
}
func (this *E日期时间型) E取时间戳纳秒() int64 {
return this.Time.TimestampNano()
}
func (this *E日期时间型) E时间到文本(format string) string {
if format == "" {
format = "Y-m-d H:i:s"
}
return this.Time.Format(format)
}
func (this *E日期时间型) E增减日期(年 int, 月 int, 日 int) *E日期时间型 {
this.Time = this.Time.AddDate(年, 月, 日)
return this
}
func (this *E日期时间型) E增减时间(时 int, 分 int, 秒 int) *E日期时间型 {
if 时 != 0 {
this.Time.AddStr(E到文本(时) + "h")
}
if 分 != 0 {
this.Time.AddStr(E到文本(分) + "m")
}
if 秒 != 0 {
this.Time.AddStr(E到文本(秒) + "s")
}
return this
}
func (this *E日期时间型) E大于(time *E日期时间型) bool {
return this.Time.After(time.Time)
}
func (this *E日期时间型) E小于(time *E日期时间型) bool {
return this.Time.Before(time.Time)
}
func (this *E日期时间型) E等于(time *E日期时间型) bool {
return this.Time.Equal(time.Time)
}
// 返回当前区域设置中可读格式的差异。
// 将过去的值与现在的默认值进行比较时:
// 1 小时前
// 5 个月前
// 将将来的值与现在的默认值进行比较时:
// 1 小时后
// 5 个月后
// 将过去的值与另一个值进行比较时:
// 1 小时前
// 5 个月前
// 将将来的值与另一个值进行比较时:
// 1 小时后
// 5 个月后
func (this *E日期时间型) E到友好时间(d *E日期时间型) string {
return "暂时没有编写"
}
//到时间
//增减时间
//取时间间隔
//取某月天数
//时间到文本
//取时间部分
func E取现行时间() *E日期时间型 {
this := new(E日期时间型)
this.Time = gtime.Now()
return this
}
func E到时间(s string) *E日期时间型 {
this := new(E日期时间型)
if t, err := gtime.StrToTime(s); err == nil {
this.Time = t
}
return this
}
func E到时间从时间戳(s int64) *E日期时间型 {
this := new(E日期时间型)
this.Time = gtime.NewFromTimeStamp(s)
return this
}