-1

I want to add 30 minutes to the current time.

I tried this

NSDate *dateToFire = [[NSDate date] dateByAddingTimeInterval:5*60];

BUt just need the time like 10:00:30 ---> +30 = 10:30:00

Suggestions are always appreciated.

Thanks

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
Shishir.bobby
  • 10,994
  • 21
  • 71
  • 100

3 Answers3

4

Use this way:

NSCalendar *calendar=[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components=[NSDateComponents new];
components.minute=30;
NSDate *newDate=[calendar dateByAddingComponents: components toDate: [NSDate date] options: 0];
//To get date in  `hour:minute` format.
NSDateFormatter *dateFormatterHHMM=[NSDateFormatter new];
[dateFormatterHHMM setDateFormat:@"hh:mm"];
NSString *timeString=[dateFormatterHHMM stringFromDate:newDate];

NSLog(@"===> %@",timeString);
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • ==> 2013-01-12 08:08:35 +0000 this is the result,which i think is right, but i need to get the hour:minutes only. DO i need to break the string ?how? – Shishir.bobby Jan 12 '13 at 07:39
3

Please add it like this: 30*60. You are adding just 5 mins in your code.

The time that you are adding is in mili seconds.

So you need to try this:

NSDate *dateToFire = [[NSDate date] dateByAddingTimeInterval:30*60];

This will add 30 minutes in the current time.

iCreative
  • 1,499
  • 1
  • 9
  • 22
1

Try this ::

NSDate *dateToFire = [[NSDate date] dateByAddingTimeInterval:1800.0];

Hopefully, It'll help you. Thanks.

Manann Sseth
  • 2,745
  • 2
  • 30
  • 50