-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime.go
More file actions
37 lines (32 loc) · 663 Bytes
/
time.go
File metadata and controls
37 lines (32 loc) · 663 Bytes
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
package cxtime
import (
"time"
cxbytes "github.com/cloudxaas/gobytes"
)
func NanoNow() uint64 {
return uint64(time.Now().UnixNano())
}
func NanoNowBytes() []byte {
return cxbytes.Uint64ToBytes(NanoNow())
}
func YearNow(buf []byte) []byte {
now := time.Now().Year()
for i := len(buf) - 1; i >= 0; i-- {
buf[i] = byte(now%10) + '0'
now /= 10
if now == 0 {
return buf[i:]
}
}
return nil
}
func YearNowString() string {
year := time.Now().Year()
buf := [4]byte{
byte(year/1000) + '0',
byte((year/100)%10) + '0',
byte((year/10)%10) + '0',
byte(year%10) + '0',
}
return string(buf[:])
}