Instagram 媒体 ID 到时间戳的转换
Instagram media ID to timestamp conversion
Instagram 在此博客中解释了他们如何创建媒体 ID post
https://instagram-engineering.com/sharding-ids-at-instagram-1cf5a71e5a5c
Each of our IDs consists of: 41 bits for time in milliseconds (gives
us 41 years of IDs with a custom epoch) 13 bits that represent the
logical shard ID 10 bits that represent an auto-incrementing sequence,
modulus 1024. This means we can generate 1024 IDs, per shard, per
millisecond.
our ‘epoch’ begins on January 1st, 2011
not sure if that's the actual production value or only for the example
如何从媒体 ID 取回时间戳?
我有这两个媒体 ID,我知道时间戳,但我需要从其他人那里提取它
2384288897814875714 2020-08-26T13:43:27Z
2383568809444681765 2020-08-25T13:52:46Z
package main
import (
"fmt"
"time"
)
const (
instaEpoch int64 = 1314220021721
mediaID int64 = 2384288897814875714
)
func main() {
extractedTimestamp := mediaID >> (64-41)
timeFromMediaID := extractedTimestamp + instaEpoch
fmt.Println(time.Unix(timeFromMediaID/1000,0).UTC())
}
输出:
2020-08-26 13:43:27 +0000 UTC
您只需右移 id 即可取回时间戳。然后你必须将毫秒添加到 instagram 正在使用的时代。
Instagram 在此博客中解释了他们如何创建媒体 ID post
https://instagram-engineering.com/sharding-ids-at-instagram-1cf5a71e5a5c
Each of our IDs consists of: 41 bits for time in milliseconds (gives us 41 years of IDs with a custom epoch) 13 bits that represent the logical shard ID 10 bits that represent an auto-incrementing sequence, modulus 1024. This means we can generate 1024 IDs, per shard, per millisecond.
our ‘epoch’ begins on January 1st, 2011 not sure if that's the actual production value or only for the example
如何从媒体 ID 取回时间戳?
我有这两个媒体 ID,我知道时间戳,但我需要从其他人那里提取它
2384288897814875714 2020-08-26T13:43:27Z
2383568809444681765 2020-08-25T13:52:46Z
package main
import (
"fmt"
"time"
)
const (
instaEpoch int64 = 1314220021721
mediaID int64 = 2384288897814875714
)
func main() {
extractedTimestamp := mediaID >> (64-41)
timeFromMediaID := extractedTimestamp + instaEpoch
fmt.Println(time.Unix(timeFromMediaID/1000,0).UTC())
}
输出:
2020-08-26 13:43:27 +0000 UTC
您只需右移 id 即可取回时间戳。然后你必须将毫秒添加到 instagram 正在使用的时代。