作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
:a, "20th Apr, 2013" => :b,"Tomorrow" => :c,"5:00 PM" => :d,"09:25-6ren">
我有一个如下所示的哈希:
{"19th Apr, 2013" => :a, "20th Apr, 2013" => :b,"Tomorrow" => :c,"5:00 PM" => :d,"09:25 PM" => :e}
我想要输出:
作为 {"5:00 PM"=> :d,"09:25 PM"=> :e}
谁能帮我解决这个问题?
最佳答案
t = {"19th Apr, 2013" => :a, "20th Apr, 2013" => :b,"Tomorrow" => :c,"5:00 PM" => :d,"09:25 PM" => :e}
t.select { |k,v| Time.strptime(k,"%H:%M %P") rescue false }
#=> {"5:00 PM"=>:d, "09:25 PM"=>:e}
关于ruby - 如何仅从哈希中提取时间项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16046722/
我是一名优秀的程序员,十分优秀!