mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-08 11:20:27 +08:00
时间可以快速获取当前小时
This commit is contained in:
@@ -36,6 +36,7 @@ type FastTime struct {
|
|||||||
unixTimeMilliString string
|
unixTimeMilliString string
|
||||||
ymd string
|
ymd string
|
||||||
round5Hi string
|
round5Hi string
|
||||||
|
hour int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFastTime() *FastTime {
|
func NewFastTime() *FastTime {
|
||||||
@@ -48,6 +49,7 @@ func NewFastTime() *FastTime {
|
|||||||
unixTimeMilliString: types.String(rawTime.UnixMilli()),
|
unixTimeMilliString: types.String(rawTime.UnixMilli()),
|
||||||
ymd: timeutil.Format("Ymd", rawTime),
|
ymd: timeutil.Format("Ymd", rawTime),
|
||||||
round5Hi: timeutil.FormatTime("Hi", rawTime.Unix()/300*300),
|
round5Hi: timeutil.FormatTime("Hi", rawTime.Unix()/300*300),
|
||||||
|
hour: rawTime.Hour(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,3 +93,7 @@ func (this *FastTime) Round5Hi() string {
|
|||||||
func (this *FastTime) Format(layout string) string {
|
func (this *FastTime) Format(layout string) string {
|
||||||
return timeutil.Format(layout, this.rawTime)
|
return timeutil.Format(layout, this.rawTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *FastTime) Hour() int {
|
||||||
|
return this.hour
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ func TestFastTime_Format(t *testing.T) {
|
|||||||
t.Log(now.Format("Y-m-d H:i:s"))
|
t.Log(now.Format("Y-m-d H:i:s"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFastTime_Hour(t *testing.T) {
|
||||||
|
var now = fasttime.Now()
|
||||||
|
t.Log(now.Hour())
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkNewFastTime(b *testing.B) {
|
func BenchmarkNewFastTime(b *testing.B) {
|
||||||
b.RunParallel(func(pb *testing.PB) {
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
for pb.Next() {
|
for pb.Next() {
|
||||||
|
|||||||
Reference in New Issue
Block a user