You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
562 B
33 lines
562 B
package times |
|
|
|
import ( |
|
"sig-pub/pkg/utils/conver" |
|
"time" |
|
) |
|
|
|
// Watch 计时器 |
|
type Watch struct { |
|
t time.Time |
|
} |
|
|
|
func NewWatch() *Watch { |
|
return &Watch{ |
|
t: time.Now(), |
|
} |
|
} |
|
|
|
// Elapsed 返回从计时开始到现在的所用时间。 |
|
func (w *Watch) Elapsed() time.Duration { |
|
return time.Since(w.t) |
|
} |
|
|
|
// Elapsed 返回从计时开始到现在的所用时间。 |
|
func (w *Watch) ElapsedFmt(sep string) string { |
|
return conver.TimeDurationFormat(w.Elapsed(), sep) |
|
} |
|
|
|
// Watch 重置计时器 |
|
func (w *Watch) Reset() *Watch { |
|
w.t = time.Now() |
|
return w |
|
}
|
|
|