timestamp.go 444 字节
Newer Older
M
Mark Haines 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
package gomatrixserverlib

import (
	"time"
)

// A Timestamp is a millisecond posix timestamp.
type Timestamp uint64

// AsTimestamp turns a time.Time into a millisecond posix timestamp.
func AsTimestamp(t time.Time) Timestamp {
	return Timestamp(t.UnixNano() / 1000000)
}

// Time turns a millisecond posix timestamp into a UTC time.Time
func (t Timestamp) Time() time.Time {
	return time.Unix(int64(t)/1000, (int64(t)%1000)*1000000).UTC()
}