在Ruby中从UUID v1中提取时间

3

我存储了一个以UUID v1作为键的数据,现在我想知道这个UUID是何时生成的。有什么好方法可以做到吗?


以下是如何在Python中完成的:https://dev59.com/Bm865IYBdhLWcg3wd-ge,可以将其用作模板。 - ThatGuyInIT
我在Python中找到了这个小技巧。由于我不擅长Ruby,能否有人为Ruby编写这个呢? - mhk
1个回答

2

这在irb中有效:

require 'simple_uuid'
uuid = SimpleUUID::UUID.new
uuid.to_guid # actually this is what I have stored in my database
Time.at(SimpleUUID::UUID.new(uuid.to_guid).seconds) # returns the time and date of the UUID

感谢我的朋友KillerFox,他向我展示了简单的解决方案。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接