You can not select more than 25 topics
Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- package fasttime
-
- import (
- "sync/atomic"
- "time"
- )
-
- func init() {
- go func() {
- ticker := time.NewTicker(time.Second)
- defer ticker.Stop()
- for tm := range ticker.C {
- t := uint64(tm.Unix())
- atomic.StoreUint64(¤tTimestamp, t)
- }
- }()
- }
-
- var currentTimestamp = uint64(time.Now().Unix())
-
- // UnixTimestamp returns the current unix timestamp in seconds.
- //
- // It is faster than time.Now().Unix()
- func UnixTimestamp() uint64 {
- return atomic.LoadUint64(¤tTimestamp)
- }
-
- // UnixDate returns date from the current unix timestamp.
- //
- // The date is calculated by dividing unix timestamp by (24*3600)
- func UnixDate() uint64 {
- return UnixTimestamp() / (24 * 3600)
- }
-
- // UnixHour returns hour from the current unix timestamp.
- //
- // The hour is calculated by dividing unix timestamp by 3600
- func UnixHour() uint64 {
- return UnixTimestamp() / 3600
- }
|