Negative date issue on iPad, not on simulator

I am working on a historical application, so I need to deal with the date before and after JC.

I am trying to parse a string with the form "01/01 / -200", but it returns a null date while it works with "01/01/200".

Here is my code:

NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc]init] autorelease];
[dateFormatter setDateFormat:@"dd/MM/y"]; // @TODO Get negative date
[dateFormatter setLenient:NO];

NSDate* date = [dateFormatter dateFromString:dateString];
return date;

I am also trying to use the form "01/01/200 BC" setDateFormat:@"dd/MM/y G", but I cannot get it to work. As mvds suggests in my answer, I tried the “01/01/200 BC” format on the simulator and it works ... the problem only occurs on my iPad (version 3.2.1)

Do you have an idea how to do it right?

+3
source share
2

- . , iPad -, Era :

  • BC - "av. J.-C."
  • AD - "ap. J.-C."

XML , .

AD-BC, :

+ (NSString*) convertIntoBCADString:(NSString*) originalString 
{
    NSString* newString = [originalString stringByReplacingOccurrencesOfString:@"av. J.-C." withString:@"BC"];
    return [newString stringByReplacingOccurrencesOfString:@"ap. J.-C." withString:@"AD"]; 
}
+1

:

NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc]init] autorelease];
[dateFormatter setDateFormat:@"dd/MM/y G"];
NSDate *date = [dateFormatter dateFromString:@"01/01/200 BC"];
NSLog(@"refdate %@",[dateFormatter stringFromDate:date]);
date = [date addTimeInterval:24*3600*365*2];
NSLog(@"2 years later %@",[dateFormatter stringFromDate:date]);

:

refdate 01/01/200 BC
2 years later 01/01/198 BC

3.2, iPad , SDK, iPad . , ?

+2

Source: https://habr.com/ru/post/1757411/


All Articles