You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
361 B
Go
23 lines
361 B
Go
3 years ago
|
package timex
|
||
|
|
||
|
import "time"
|
||
|
|
||
|
const (
|
||
|
seconds = 1e11
|
||
|
milliseconds = 1e14
|
||
|
microseconds = 1e17
|
||
|
)
|
||
|
|
||
|
func TimestampToTime(ts int64) time.Time {
|
||
|
if ts < seconds {
|
||
|
return time.Unix(ts, 0)
|
||
|
}
|
||
|
if ts < milliseconds {
|
||
|
return time.Unix(ts/1000, (ts%1000)*1e6)
|
||
|
}
|
||
|
if ts < microseconds {
|
||
|
return time.Unix(ts/1e6, (ts%1e6)*1000)
|
||
|
}
|
||
|
return time.Unix(0, ts)
|
||
|
}
|