Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

looking for a method that will show tomorrow's date in ruby

Though, I already got the answer to my question, I decided to edit it.

I was looking for any method in Ruby that can show tomorrow's date. It's ok if it will show the time as well, I will format its output.

The Time.now gives current date, time and timezone:

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

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

It's ok if there are other methods that can do it.

like image 260
Askar Avatar asked Jun 11 '13 04:06

Askar


People also ask

What does DateTime now return in Ruby?

DateTime#now() : now() is a DateTime class method which returns a DateTime object denoting the given calendar date. Return: DateTime object denoting the given calendar date.


2 Answers

require 'date'

tomorrow = Date.today + 1

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

like image 115
TheOneTeam Avatar answered Oct 06 '22 03:10

TheOneTeam


Try:

Time.now + 24*60*60

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

like image 45
Stu Gla Avatar answered Oct 06 '22 04:10

Stu Gla