NSDateFormatter producing (null) SQLite and iOS 5.1

前端 未结 2 482
说谎
说谎 2020-12-04 03:01

Maybe somebody can help explain why I am getting a null value when converting a string to a date. It all looks right but I\'m obviously missing something here.

Some

相关标签:
2条回答
  • 2020-12-04 03:37

    I changed your date format to HH not hh and it works. Here is my test code....

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];  // SQLite default date format
    
    
    // test SQLite as String
    NSString *testDate = @"2012-04-23 18:20:51";
    
    
    
    NSDate *aDate = [formatter dateFromString:testDate];
    
    NSLog(@"Using formmater on string date results in: %@", aDate);
    
    0 讨论(0)
  • 2020-12-04 03:45

    NSDateFormatter uses the format patterns from the Unicode Technical Standard #35.

    For the hour format, you need HH (Hour [0-23]) not hh (Hour [1-12]).

    0 讨论(0)
提交回复
热议问题