NSDateFormatter dateFromString and iPhone in 24 Hour Format Confusion

前端 未结 5 1637
小蘑菇
小蘑菇 2020-12-03 05:04

I\'m having a problem. I get incoming time strings in 12-hour format, and I\'m turning them into NSDate objects. When the iPhone is in 12 hour format, no problem. But when i

5条回答
  •  佛祖请我去吃肉
    2020-12-03 05:32

    Okay, I left a comment, but it squished all the code together, so I'll have to "answer" my question with a comment:

    Thanks. I gave it a whirl with this code:

    NSString *theTime = @"3:19 PM"; 
    NSDateFormatter *timeFormatter = [[[NSDateFormatter alloc] init] autorelease];       
    [timeFormatter setTimeStyle:NSDateFormatterShortStyle]; 
    [timeFormatter setDateStyle:NSDateFormatterNoStyle]; 
    NSDate *date = [timeFormatter dateFromString:theTime]; 
    NSString *theString = [timeFormatter stringFromDate:date]; 
    

    And date comes up nil. I ran into this earlier when I tried this route, and it's not working. Very frustrating.

提交回复
热议问题