DateTime.iso8601('2014-07-08T17:51:36.000Z') 结果为 NoMethodError?
DateTime.iso8601('2014-07-08T17:51:36.000Z') results in NoMethodError?
我似乎无法让 DateTime 处理合法的 ISO-8601 字符串。
jruby-1.7.19 :013 > DateTime.iso8601('2014-07-08T17:51:36.000Z')
NoMethodError: undefined method `/' for "000":String
from /Users/robert.kuhar/.rvm/rubies/jruby-1.7.19/lib/ruby/1.9/date.rb:1778:in `new_by_frags'
from /Users/robert.kuhar/.rvm/rubies/jruby-1.7.19/lib/ruby/1.9/date.rb:1829:in `iso8601'
from (irb):13:in `evaluate'
from org/jruby/RubyKernel.java:1107:in `eval'
from org/jruby/RubyKernel.java:1507:in `loop'
from org/jruby/RubyKernel.java:1270:in `catch'
from org/jruby/RubyKernel.java:1270:in `catch'
from /Users/robert.kuhar/.rvm/rubies/jruby-1.7.19/bin/irb:13:in `(root)'
我该如何挖掘它?
我不知道为什么 DateTime.iso8601
在 JRuby 下会出错,但您可以改用 DateTime.parse
:
d = DateTime.parse '2014-07-08T17:51:36.000Z'
puts d.to_s #=> "2014-07-08T17:51:36+00:00"
我似乎无法让 DateTime 处理合法的 ISO-8601 字符串。
jruby-1.7.19 :013 > DateTime.iso8601('2014-07-08T17:51:36.000Z')
NoMethodError: undefined method `/' for "000":String
from /Users/robert.kuhar/.rvm/rubies/jruby-1.7.19/lib/ruby/1.9/date.rb:1778:in `new_by_frags'
from /Users/robert.kuhar/.rvm/rubies/jruby-1.7.19/lib/ruby/1.9/date.rb:1829:in `iso8601'
from (irb):13:in `evaluate'
from org/jruby/RubyKernel.java:1107:in `eval'
from org/jruby/RubyKernel.java:1507:in `loop'
from org/jruby/RubyKernel.java:1270:in `catch'
from org/jruby/RubyKernel.java:1270:in `catch'
from /Users/robert.kuhar/.rvm/rubies/jruby-1.7.19/bin/irb:13:in `(root)'
我该如何挖掘它?
我不知道为什么 DateTime.iso8601
在 JRuby 下会出错,但您可以改用 DateTime.parse
:
d = DateTime.parse '2014-07-08T17:51:36.000Z'
puts d.to_s #=> "2014-07-08T17:51:36+00:00"