ruby - 如何修复 "uninitialized constant Context::DateTime"错误?

标签 ruby datetime

我在 Ruby 中遇到了一个未初始化的常量 Context::DateTime 错误。我的代码是:

# Print data about a list of Tweets
def print_timeline(tweets)
  tweets.each do |tweet|
    d = datetime.new(tweet['created_at'])
    puts "#{tweet['user']['name']} , #{tweet['text']} , #{d.strftime('%m.%d.%y')} , #{tweet['id']}"
  end
end

我相信它是在说它找不到 DateTime 类,我不确定为什么。我是 Ruby 新手。

最佳答案

DateTime 应该大写,就像您的问题标题一样。您还可能需要添加:

require "date"

关于ruby - 如何修复 "uninitialized constant Context::DateTime"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17065666/

相关文章:

python - pandas 日期时间轴上的刻度标签与刻度不对齐

ruby-on-rails - rake 任务因 US-ASCII 中的无效字节序列而失败

ruby-on-rails - 如何突出显示 Rails 验证错误的字段

Ruby 断管 @io_write - <STDOUT>

Python:根据季度数计算月份、季度详细信息

Python Pandas 日期时间索引创建数据框

sql - 如何将 Sql Server 2008 DateTimeOffset 转换为 DateTime

c# - 为什么 DateTime 基于 Ticks 而不是毫秒?

ruby - Rails 3.2.8 与 Ruby 1.9.3 兼容吗?

Mysql 到 PostgreSql Rails 3 heroku 应用程序 true/false