从 ruby​​ 中的 UUID v1 中提取时间 [英] Extract time from a UUID v1 in ruby

查看:22
本文介绍了从 ruby​​ 中的 UUID v1 中提取时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我存储了以 UUID v1 作为键的数据,现在我想知道 UUID 是何时生成的.我该如何做到这一点?

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?

推荐答案

这适用于 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,他向我展示了简单的解决方案.

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

这篇关于从 ruby​​ 中的 UUID v1 中提取时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆