Extract time from a UUID v1 in ruby

2019-05-10 20:36发布

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?

标签: ruby time uuid
1条回答
做自己的国王
2楼-- · 2019-05-10 21:14

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.

查看更多
登录 后发表回答