Jump to content

Quick NSString parseing question


yaazz
 Share

1 post in this topic

Recommended Posts

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

 Share

×
×
  • Create New...