Loading...

Python TimeUUID

Temperature: 0 °C

蘇恆永 蘇恆永
author_tools

參考這一篇:
什麼時候讓用 time UUID,Url link 

StackOverflow 有人提供了一段 code:
Url link


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

實用的 netstat 查詢連線指令

實用的 netstat 查詢...

以下是一些實用的 netstat 語法,可以檢查主機的連線數量: netstat na 顯示主機上所...

一堆設計資源, 記錄一下

一堆設計資源, 記錄一下

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

Python Pragmatic Unicode

Python Pragmat...

記錄一下 Python Pragmatic Unicode ...

Recommended reading

Other stories happened at this address

Python Pragmatic Unicode

Python Pragmat...

記錄一下 Python Pragmatic Unicode ...

Python Pragmatic Unicode

Python Pragmat...

記錄一下 Python Pragmatic Unicode ...

免費電子書下載

免費電子書下載

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

CentOS 5 更新 openssh 7.1p2 及 openssl 1.0.1s

CentOS 5 更新 op...

最近被 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