Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with date and time

  1. I have a UTC date of Tue, 16 Feb 2010 03:12:02 UTC +00:00, for example.
  2. I want to add 168 hours to this date to get a future UTC date.
  3. What's the best way to do that?
like image 440
keruilin Avatar asked Dec 23 '22 05:12

keruilin


1 Answers

You tagged the question rails so here is how you can do this in Rails, using some of the helpers:

time_string = 'Tue, 16 Feb 2010 03:12:02 UTC +00:00'
new_time = Time.parse( time_string ) + 168.hours

If you already have it as a Time object, just add the 168.hours:

new_time = old_time + 168.hours

Or you can just add 1.week:

new_time = old_time + 1.week
like image 143
Doug Neiner Avatar answered Jan 06 '23 03:01

Doug Neiner