-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtime.go
More file actions
111 lines (85 loc) 路 1.74 KB
/
Copy pathtime.go
File metadata and controls
111 lines (85 loc) 路 1.74 KB
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
package gouse
import (
"fmt"
"time"
)
func Second() int {
return time.Now().Second()
}
func Minute() int {
return time.Now().Minute()
}
func Hour() int {
return time.Now().Hour()
}
func Day() int {
return time.Now().Day()
}
func Month() int {
return int(time.Now().Month())
}
func Year() int {
return time.Now().Year()
}
func Weekday() int {
return int(time.Now().Weekday())
}
func Unix() int64 {
return time.Now().Unix()
}
func Milli() int64 {
return time.Now().UnixNano() / int64(time.Millisecond)
}
func Micro() int64 {
return time.Now().UnixNano() / int64(time.Microsecond)
}
func Nano() int64 {
return time.Now().UnixNano()
}
func Milli2Time(milli int64) time.Time {
return time.Unix(0, milli*int64(time.Millisecond))
}
func Micro2Time(micro int64) time.Time {
return time.Unix(0, micro*int64(time.Microsecond))
}
func Nano2Time(nano int64) time.Time {
return time.Unix(0, nano)
}
func ToSecond(second int) time.Duration {
return time.Duration(second) * time.Second
}
func ToMinute(minute int) time.Duration {
return time.Duration(minute) * time.Minute
}
func ToHour(hour int) time.Duration {
return time.Duration(hour) * time.Hour
}
func SleepS(second int) {
time.Sleep(ToSecond(second))
}
func SleepM(minute int) {
time.Sleep(ToMinute(minute))
}
func SleepH(hour int) {
time.Sleep(ToHour(hour))
}
func TerminalClock() {
msgTime := make(chan time.Time)
go func() {
for {
time.Sleep(1 * time.Second)
msgTime <- time.Now()
}
}()
for t := range msgTime {
Cls()
fmt.Println(Time2Str(t))
}
}
func DiffTime(t1, t2 time.Time) time.Duration {
return t2.Sub(t1)
}
func DiffTimeNow(startTime time.Time) time.Duration {
elapsedTime := float64(time.Since(startTime).Seconds() * 1000)
return time.Duration(elapsedTime)
}