为什么“Time.now.at_beginning_of_day”不起作用?

时间:2010-11-25 02:52:56

标签: ruby-on-rails ruby ruby-on-rails-3

我使用了这样的代码:

puts Time.now.at_beginning_of_day

但似乎Ruby没有这种方法。我搜索谷歌找到它。用的东西错了吗?

2 个答案:

答案 0 :(得分:2)

它是Active Support的一部分。

请参阅Active Support Core Extensions,尤其是DateTimeTime次转化。

请注意文档开头部分中有关要求Active Support支持更好粒度的更改的部分。

答案 1 :(得分:1)

这些是你的方法好先生。您需要为该Time对象编写方法。

ruby-1.9.2-p0 > Time.now.methods
 => [:to_i, :to_f, :to_r, :<=>, :eql?, :hash, :localtime, :gmtime, :utc, :getlocal, :getgm, :getutc, :ctime, :asctime, :to_s, :inspect, :to_a, :+, :-, :succ, :round, :sec, :min, :hour, :mday, :day, :mon, :month, :year, :wday, :yday, :isdst, :dst?, :zone, :gmtoff, :gmt_offset, :utc_offset, :utc?, :gmt?, :sunday?, :monday?, :tuesday?, :wednesday?, :thursday?, :friday?, :saturday?, :tv_sec, :tv_usec, :usec, :tv_nsec, :nsec, :subsec, :strftime, :_dump, :==, :>, :>=, :<, :<=, :between?, :nil?, :===, :=~, :!~, :class, :singleton_class, :clone, :dup, :initialize_dup, :initialize_clone, :taint, :tainted?, :untaint, :untrust, :untrusted?, :trust, :freeze, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :public_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :instance_variable_defined?, :instance_of?, :kind_of?, :is_a?, :tap, :send, :public_send, :respond_to?, :respond_to_missing?, :extend, :display, :method, :public_method, :define_singleton_method, :__id__, :object_id, :to_enum, :enum_for, :equal?, :!, :!=, :instance_eval, :instance_exec, :__send__]