I want to get a string of the current time in Ruby:
"Time is " + Time.new.month + "/" + Time.new.day + "/" + Time.new.year
But it says "can't convert Fixnum into String". How can I fix this?
Or you could just use right tool for the job: time formatting.
Time.new.strftime "Time is %m/%d/%Y" # => "Time is 11/13/2012"
You could use to_s
"Time is " + Time.new.month.to_s + "/" + Time.new.day.to_s + "/" + Time.new.year.to_s
But event better is to use strftime
Time.new.strftime("Time is %-m/%e/%Y")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With