Loading...

Python TimeUUID

Temperature: 0 °C

蘇恆永 蘇恆永
author_tools
參考這一篇:
什麼時候讓用 time UUID,連結網址 

StackOverflow 有人提供了一段 code:
連結網址


public static String reorderTimeUUId(String originalTimeUUID)
    {
        StringTokenizer tokens = new StringTokenizer(originalTimeUUID, "-");
        if (tokens.countTokens() == 5)
        {
            String time_low = tokens.nextToken();
            String time_mid = tokens.nextToken();
            String time_high_and_version = tokens.nextToken();
            String variant_and_sequence = tokens.nextToken();
            String node = tokens.nextToken();

            return time_high_and_version + '-' + time_mid + '-' + time_low + '-' + variant_and_sequence + '-' + node;

        }

        return originalTimeUUID;
    }


把它翻成 python :

def getTimeUUID(uuidVar)
    # ref: http://stackoverflow.com/questions/8713873/is-python-uuid1-sequential-as-timestamps
    import uuid
    if not isinstance(uuidVar, uuid.UUID):
        uuidVar = uuid.uuid1()
    tmp = str(uuidVar)

    tokens = tmp.split("-")
    if len(tokens) == 5:
        time_low, time_mid, time_high_and_version, variant_and_sequence, node = tokens
        return time_high_and_version + '-' + time_mid + '-' + time_low + '-' + variant_and_sequence + '-' + node
    return tmp




原理是原本的 UUID (uuid1) 組合是:
time_low – time_mid – time_high_and_version – variant_and_sequence – node

轉成
time_high_and_version – time_mid – time_low – variant_and_sequence – node

這樣產生出來的 UUID 就可以按時間排序了.

三重湯城園區 Go

https://innstory.com/story-Python_TimeUUID-557

Prev
 Python_Pragmatic_Unicode

Next
免費電子書下載 

Nearby Attractions

三重湯城園區-Nearby Attractions

  • 淡水海關碼頭 Go
  • 學海書院(今高氏宗祠) Go
  • 滬尾水道 Go
  • 淡水公司田溪橋遺蹟 Go
  • 新莊文昌祠 Go
  • 馬偕墓 Go

About the Author

蘇恆永

重新 pickup 本能中

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

一堆設計資源, 記錄一下

一堆設計資源, 記錄一下

設計資源總匯 奧革設計 奧革設計團隊精心整理的設計師必備設計資源,收藏各式各樣的靈感、...

ankhsvn 使用非標準 ssh port, 及設定免密碼登入

ankhsvn 使用非標準 ssh port, 及設定免密碼登入

ankhsvn https://ankhsvn.open.collab.net/...

CentOS 5 更新 openssh 7.1p2 及 openssl 1.0.1s

CentOS 5 更新 openssh 7.1p2 及 openssl 1.0.1s

最近被 highlight openssh 必須更新至 .p. CentOS 真是有夠...

Recommended reading

Other stories happened at this address

CentOS 5 更新 openssh 7.1p2 及 openssl 1.0.1s

CentOS 5 更新 openssh 7.1p2 及 openssl 1.0.1s

最近被 highlight openssh 必須更新至 .p. CentOS 真是有夠...

免費電子書下載

免費電子書下載

太晚看到了, 每天都有免費程式設計相關的電子書可以下載 https://www....

Python Pragmatic Unicode

Python Pragmatic Unicode

記錄一下 Python Pragmatic Unicode http://...

CentOS 5 更新 openssh 7.1p2 及 openssl 1.0.1s

CentOS 5 更新 openssh 7.1p2 及 openssl 1.0.1s

最近被 highlight openssh 必須更新至 .p. CentOS 真是有夠...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format