Friday, 6 September 2013

compare between two "24h format" date in objective C

compare between two "24h format" date in objective C

I have an array containing with some 24h formate time.
Like :
08.00
09.00
10.00
12.00
13.00
14.00
14.15
14.30
14.50
15.00
16.00
17.00
& say "ArrayTime" holds everytime of this array as a string. I have an
another string "CurrentTime" which contain the current device time in 24h
format. I get the value of it, from bellow method :
-(void) currentTimePicker
{
NSDate *currentDateTime = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"HH:mm"];
CurrentTime = [dateFormatter stringFromDate:currentDateTime];
}
Now i want to compare between them and want to show the running time & All
"next time" list from the array.
Like : If now is "14.00" By comparing i will show :
14.00
14.15
14.30
14.50
15.00
16.00
17.00
from the array. But here when i want to compare them it only compare the
1st part of the time (Hour part).
Like :
14.00
15.00
16.00
17.00
Escaping this times:
14.15
14.30
14.50
Here is my compare code:
NSComparisonResult result = [CurrentTime compare:ArrayTime];
if (result == NSOrderedAscending || result == NSOrderedSame)
{
}
So, How can i compare the full length of time, i mean for hour part
(00.--) and minute part (--.00) together? If any one similar to this issue
please share with me. Thanks a lot in advance. - Tulon

No comments:

Post a Comment