简体   繁体   English

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

[英]How to extract time information from uuid in python

I'm trying to find an equivalent option of "uuid -d" linux command in python, and end up using below, as found in Extract the time from a UUID v1 in python : 我试图在python中找到等效的“ uuid -d” linux命令选项,并最终使用下面的方法,如在python中从UUID v1中提取时间所示

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

which printed the time as "2018-05-27 15:40:31.803023", which is different from the actual time shows up in "uuid -d" command: 将时间打印为“ 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

Is there a correct option to extract time information from UUID in python, using uuid or any built-in modules? 是否存在使用uuid或任何内置模块从python中的UUID提取时间信息的正确选项?

Your provided request_id is different from the uuid you test using uuid -d . 您提供的request_id与您使用uuid -d测试的uuid不同。 If you correct this discrepancy they correspond (checked using answers to Extract the time from a UUID v1 in python ). 如果您纠正了这种差异,它们就会对应(使用从python中的UUID v1中提取时间的答案进行检查)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM