如何从 python 中的 uuid 中提取时间信息

How to extract time information from uuid in python

我试图在 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

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

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