NSDateFormatter Error. How so?

    NSDateFormatter *timeFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [timeFormatter setDateFormat:@"h:mm a"];
    NSString *fullTime = [timeFormatter stringFromDate:someDateHere];
    NSArray *timeParts = [fullTime componentsSeparatedByString:@" "];
    timeLabel.text = [timeParts objectAtIndex:0];
    ampmLabel.text = [timeParts objectAtIndex:1];

LAST crash using

    NSRangeException*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]

How is this possible? On the date that comes back immediately before this code, there is a zero check.

+3
source share
2 answers

In the documentation for the data formatting format (section "Date Formats"> "Use Formatted Strings to Specify Custom Formats"> "Fixed Formats"):

, NSDateFormater - ( ).... iOS AM/PM 24- . , NSDateFormatter .

, iOS, 24- , "6:02 PM", "18:02", "h: mm ". , , "18:02", .

+3

NSDateFormatter , :

, (setDateFormat:) , - . .

- ? ( 1 , , , .) , .

, strftime_l /. . ( , AM/PM , ? ? 24- ...)

+1

All Articles