Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do fix "uninitialized constant Context::DateTime" error?

Tags:

datetime

ruby

I am running into a uninitialized constant Context::DateTime error in Ruby. My code is:

# 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

I believe it is saying it cannot find the DateTime class, and I am not sure why. I am new to Ruby.

like image 439
cmart Avatar asked Dec 09 '25 23:12

cmart


1 Answers

DateTime should be capitalized, just like in the title of your question. Also you may have to add a:

require "date"
like image 147
Ivaylo Strandjev Avatar answered Dec 12 '25 23:12

Ivaylo Strandjev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!