【问题标题】:How to extract time information from uuid in python如何从python中的uuid中提取时间信息
【发布时间】:2018-05-27 12:25:22
【问题描述】:

我正在尝试在 python 中找到“uuid -d”linux 命令的等效选项,并最终使用下面,如Extract the time from a UUID v1 in python 中所示:

request_id = 78577992-6170-11e8-a1e4-f3a982af936e
request_uuid = uuid.UUID(request_id)
print (datetime.fromtimestamp((request_uuid.time - 0x01b21dd213814000L)*100/1e9))

将时间打印为“2018-05-27 15:40:31.803023”,与“uuid -d”命令中显示的实际时间不同:

uuid -d 78577992-6170-11e8-a1e4-f3a982af936e |grep "content: time:"
    content: time:  2018-05-27 05:40:31.803022.6 UTC

是否有正确的选项可以使用 uuid 或任何内置模块从 python 中的 UUID 中提取时间信息?

【问题讨论】:

    标签: python time uuid


    【解决方案1】:

    您提供的request_id 与您使用uuid -d 测试的uuid 不同。如果您更正此差异,则它们对应(使用Extract the time from a UUID v1 in python 的答案进行检查)。

    【讨论】:

    • 我的错……用我正在处理的实际 UUID 纠正了这个问题。
    • 而且,就是这样!!,部分原因是我用来比较的 UUID 错误,部分原因是“uuid -d”打印的是 UTC 时间,而 python 中的 UUID当地时区。一旦我用“datetime.utcfromtimestamp”结束了提取的时间,它就会正确显示。谢谢指点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-02
    • 1970-01-01
    • 2017-10-17
    • 2010-11-11
    • 1970-01-01
    • 1970-01-01
    • 2021-09-27
    相关资源
    最近更新 更多