【问题标题】:NoMethodError at / undefined method `-@' for #<DateTime:0x00000001f18168>NoMethodError at / undefined method `-@' for #<DateTime:0x00000001f18168>
【发布时间】:2012-02-01 07:15:27
【问题描述】:

我正在尝试通过独立的 ActiveSupport 使用 time.ago,因此需要:

ruby
require 'active_support/core_ext/date_time/calculations'

如果我尝试按照建议使用它:

ruby
time = Chronic.parse(time_string)
time.ago

我收到此错误:

ArgumentError - wrong number of arguments (0 for 1):
    /home/user/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.0/lib/active_support/core_ext/date_time/calculations.rb:61:in `ago'

如果我提供一个参数,那么:

ruby
time.ago DateTime.now

我得到了这个,我完全不明白:

NoMethodError - undefined method `-@' for #<DateTime:0x00000001f18168>:
    /home/passcod/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.0/lib/active_support/core_ext/date_time/calculations.rb:62:in `ago'

【问题讨论】:

    标签: ruby datetime activesupport


    【解决方案1】:

    ago 方法旨在让您能够将秒数(或其他时间单位)添加到当前时间,例如10.minutes.ago.

    不支持提供完整的日期,据我所知没有意义 - 2012 年 1 月 23 日下午 2 点之前是什么意思?

    【讨论】:

      猜你喜欢
      • 2015-03-19
      • 2016-08-13
      • 1970-01-01
      • 1970-01-01
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多