initial import
This commit is contained in:
38
core/utils/times.go
Normal file
38
core/utils/times.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"zero/core/timex"
|
||||
)
|
||||
|
||||
type ElapsedTimer struct {
|
||||
start time.Duration
|
||||
}
|
||||
|
||||
func NewElapsedTimer() *ElapsedTimer {
|
||||
return &ElapsedTimer{
|
||||
start: timex.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
func (et *ElapsedTimer) Duration() time.Duration {
|
||||
return timex.Since(et.start)
|
||||
}
|
||||
|
||||
func (et *ElapsedTimer) Elapsed() string {
|
||||
return timex.Since(et.start).String()
|
||||
}
|
||||
|
||||
func (et *ElapsedTimer) ElapsedMs() string {
|
||||
return fmt.Sprintf("%.1fms", float32(timex.Since(et.start))/float32(time.Millisecond))
|
||||
}
|
||||
|
||||
func CurrentMicros() int64 {
|
||||
return time.Now().UnixNano() / int64(time.Microsecond)
|
||||
}
|
||||
|
||||
func CurrentMillis() int64 {
|
||||
return time.Now().UnixNano() / int64(time.Millisecond)
|
||||
}
|
||||
Reference in New Issue
Block a user