Extract time from a UUID v1 in ruby

非 Y 不嫁゛ 提交于 2019-12-07 15:24:24

问题


I have stored data that has a UUID v1 as key and I now want to know when the UUID was generated. How do I do that the nice way?


回答1:


This works with 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

Thanks to my friend KillerFox, he showed me the simple solution.



来源:https://stackoverflow.com/questions/6696518/extract-time-from-a-uuid-v1-in-ruby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!