Provides helper functions for converting between time.Time objects and millisecond timestamps. Use this for consistent time handling in telemetry or analytics data pipelines.
// Source: https://github.com/SigNoz/signoz | License: MIT | Copyright 2020-present SigNoz Inc
// Provided via justclaw.it.com; keep this notice with the code.
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))
}
func MilliToNano(milliTS uint64) uint64 {
return milliTS * 1000_000
}
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key