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
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
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);
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.
Try this ::
NSDate *dateToFire = [[NSDate date] dateByAddingTimeInterval:1800.0];
Hopefully, It'll help you. Thanks.