如何在 Ruby 1.9.3 中获取今天的日期?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15366865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 05:49:22  来源:igfitidea点击:

How to get today's date in Ruby 1.9.3?

rubydate

提问by joslinm

I'm using Ruby 1.9.3, and when I execute Date.today, I get NoMethodError: undefined methodtoday' for Date:Class`

我正在使用 Ruby 1.9.3,当我执行时Date.today,我得到了NoMethodError: undefined method今天的 Date:Class`

I'm pretty confused about this since it does appear to be in the documentation. Though I know this is the documentation for 2.0, but I see answers ranging back to when it was implemented in 1.8.7. Was this removed in 1.9?

我对此很困惑,因为它似乎在文档中。虽然我知道这是 2.0 的文档,但我看到的答案可以追溯到它在 1.8.7 中实现的时间。这是在 1.9 中删除的吗?

回答by Intrepidd

Did you require 'date'?

你有require 'date'吗?

> require 'date'
 => true
> Date.today
 => #<Date: 2013-03-12 ((2456364j,0s,0n),+0s,2299161j)>