Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add time in current time

I'm quite confused about this one.

I want to grab, current time, than according to condition, I want to add the required time, to the current time. for example.

current time  = 06:47:10 
//or should i hv to change this format to "2011-03-26 06:47:10  GMT"

 if(a= 1 and b= min ) 
  { //add 1 min to
  current time 
  } 
  else if(a= 1 and b= hour) 
  { //add 1
   hour to current time 
  } 
 else if(a= 1 and b=week )  
 { //add 1
 week to current time  
 }

Just need to add the output of the above condition to current time.

Please guide me with this.

Regards

like image 426
Shishir.bobby Avatar asked Mar 26 '11 06:03

Shishir.bobby


People also ask

How do you add time to time?

Explanation: To add time, you add the hours together, then you add the minutes together. Because there are only 60 minutes in an hour, you cannot have a time whose minute value is greater than 60. In this case, subtract 60 minutes and add 1 more to the hour.

How do you add hours and time?

Adding Times Add the hours. Add the minutes. If the minutes are 60 or more, subtract 60 from the minutes and add 1 to hours.

How do we calculate time?

To solve for time use the formula for time, t = d/s which means time equals distance divided by speed.


1 Answers

Do you mean current time, as in now?

If so, this will do it for you:

NSDate *now = [NSDate date]; // Grab current time
NSDate *newDate = [now addTimeInterval:XXX] // Add XXX seconds to *now

Where XXX is the time in seconds.

like image 126
Rog Avatar answered Oct 20 '22 09:10

Rog