util.go 371 B

1234567891011121314151617
  1. package discordgo
  2. import (
  3. "strconv"
  4. "time"
  5. )
  6. // SnowflakeTimestamp returns the creation time of a Snowflake ID relative to the creation of Discord.
  7. func SnowflakeTimestamp(ID string) (t time.Time, err error) {
  8. i, err := strconv.ParseInt(ID, 10, 64)
  9. if err != nil {
  10. return
  11. }
  12. timestamp := (i >> 22) + 1420070400000
  13. t = time.Unix(0, timestamp*1000000)
  14. return
  15. }