【问题标题】:Compare UUID timestamps in Python比较 Python 中的 UUID 时间戳
【发布时间】:2019-12-05 12:17:50
【问题描述】:

在 python 中,我如何比较不同 UUID 的时间戳,例如 960a1a9e-1753-11ea-a653-e4b97af3ed7ba33ba868-1753-11ea-87df-e4b97af3ed7b使用以下方式创建:

from uuid import uuid1

my_uuid = str(uuid1())

我想知道哪个是最先创建的。

如果我使用这个网站,我可以看到它的确切创建日期和时间:https://www.famkruithof.net/uuid/uuidgen

【问题讨论】:

    标签: python python-3.x timestamp uuid


    【解决方案1】:

    您可以像这样从 UUID 中获取时间戳:

    from uuid import UUID
    
    id1 = UUID('960a1a9e-1753-11ea-a653-e4b97af3ed7b')
    id2 = UUID('a33ba868-1753-11ea-87df-e4b97af3ed7b')
    print(id1.time)
    print(id2.time)
    

    文档在此处对此进行了概述:https://docs.python.org/3/library/uuid.html#uuid.UUID.fields

    时间 | 60 位时间戳

    【讨论】:

      猜你喜欢
      • 2014-04-19
      • 1970-01-01
      • 2012-07-09
      • 2013-01-12
      • 1970-01-01
      • 2015-09-22
      • 2017-06-24
      • 2018-03-10
      相关资源
      最近更新 更多