Reputation: 17512
Tue, 16 Feb 2010 03:12:02 UTC +00:00
, for example.Upvotes: 4
Views: 1618
Reputation: 757
In vanilla Ruby it's not much more difficult:
time_string = 'Tue, 16 Feb 2010 03:12:02 UTC +00:00'
new_time = DateTime.parse( time_string ) + 7
(You could just use the Date class, it would still work.)
I admit adding in hours is a little more tricky.
Upvotes: 1
Reputation: 66191
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
Upvotes: 9
Reputation: 93
FYI, '9.days' is more simpler than '168.hours'.
>> new_time = Time.parse( time_string ) + 168.hours
=> Tue Feb 23 03:12:02 UTC 2010
>> new_time = Time.parse( time_string ) + 9.days
=> Thu Feb 25 03:12:02 UTC 2010
Upvotes: 1