gpt4 book ai didi

go - Instagram 媒体 ID 到时间戳的转换

转载 作者:行者123 更新时间:2023-12-01 20:25:48 25 4
gpt4 key购买 nike

Instagram 在这篇博文中解释了他们如何创建媒体 ID

https://instagram-engineering.com/sharding-ids-at-instagram-1cf5a71e5a5c

Each of our IDs consists of: 41 bits for time in milliseconds (givesus 41 years of IDs with a custom epoch) 13 bits that represent thelogical shard ID 10 bits that represent an auto-incrementing sequence,modulus 1024. This means we can generate 1024 IDs, per shard, permillisecond.

our ‘epoch’ begins on January 1st, 2011not 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

最佳答案

playground

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 正在使用的时代。

关于go - Instagram 媒体 ID 到时间戳的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63683015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com