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

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

ankhsvn 使用非標準 ...

ankhsvn https://ankhsvn.open.c...

Python Pragmatic Unicode

Python Pragmat...

記錄一下 Python Pragmatic Unicode ...

CentOS 5 更新 openssh 7.1p2 及 openssl 1.0.1s

CentOS 5 更新 op...

最近被 highlight openssh 必須更新至 .p. CentOS5 真是有夠古老的, 一...

Recommended reading

Other stories happened at this address

免費電子書下載

免費電子書下載

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

Python Pragmatic Unicode

Python Pragmat...

記錄一下 Python Pragmatic Unicode ...

CentOS 5 更新 openssh 7.1p2 及 openssl 1.0.1s

CentOS 5 更新 op...

最近被 highlight openssh 必須更新至 .p. CentOS 真是有夠古老的, 一堆...

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