Searches for a method that displays a date in ruby

Although, I already received the answer to my question, I decided to edit it.

I was looking for any method in Ruby that can show a date tomorrow. This is normal, if it shows the time, I will format its output.

Time.now provides the current date, time, and time zone:

Time.now => 2013-06-11 13:09:02 +0900 

How can I use this method to get the date for tomorrow?

This is normal if there are other methods that can do this.

+4
source share
3 answers
 require 'date' tomorrow = Date.today + 1 

tomorrow is a date object. You can print it in the desired format.

+11
source

Try:

 Time.now + 24*60*60 

(Edited: xaxxon is right. My earlier version used Rails functionality)

+5
source

Similar to Stu Gla:

 today = Time.now tomorrow = today + (60 * 60 * 24) 

you can use the .strftime method to format ... example:

 puts tomorrow.strftime("%F") # => 2014-08-07 
+1
source

Source: https://habr.com/ru/post/1485544/


All Articles