mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-10 07:34:04 -08:00
pkg/timestamp: create timestamp package
This commit is contained in:
parent
71fe0c58a8
commit
0987a72ec9
13
pkg/timestamp/timestamp.go
Normal file
13
pkg/timestamp/timestamp.go
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package timestamp
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
// FromTime returns a new millisecond timestamp from a time.
|
||||||
|
func FromTime(t time.Time) int64 {
|
||||||
|
return t.Unix()*1000 + int64(t.Nanosecond())/int64(time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Time returns a new time.Time object from a millisecond timestamp.
|
||||||
|
func Time(ts int64) time.Time {
|
||||||
|
return time.Unix(ts/1000, (ts%1000)*int64(time.Millisecond))
|
||||||
|
}
|
Loading…
Reference in a new issue