yaazz Posted February 9, 2009 Share Posted February 9, 2009 hey there, i am trying to get the current time, then parse the hour and minute into two seperate integers I am currently using NSScanner to do this but it doesnt seem to be working right I have written this NSDate* thisDate = [NSDate date]; [NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateStyle:NSDateFormatterNoStyle]; [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; NSString* thisString = [dateFormatter stringFromDate:thisDate]; int hour,minute; bool AmPm=NO; char SamPm; NSScanner* strScan = [NSScanner scannerWithString:thisString]; [strScan scanInt:&hour]; [strScan scanInt:&minute]; /* if(SamPm == 'P') { NSLog(@"PM!!!\n"); AmPm=YES; } else if(SamPm == 'A') { NSLog(@"AM!!!!!!!"); AmPm=NO; }*/ NSLog(@"%@ Hour: %d Minute %d \n",thisString,hour,minute); but when i run it, I get "1:34 AM Hour: 1 Minute 48448 " This is close but no cigar. Can anyone tell me what im doing wrong? Link to comment Share on other sites More sharing options...
Recommended Posts