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
  • 淡水重建街16號街屋 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

Linux 連線數調校.

Linux 連線數調校.

最近常常遇到連線數太多(因為底層 WebService 太忙了). web 最後連不上的問題. 後來...

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...

免費電子書下載

免費電子書下載

太晚看到了, 每天都有免費程式設計相關的電子書可以下載 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 真是有夠古老的, 一堆...

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