Estoy seguro de que me falta algo. Pero he buscado esto en Google durante días tratando de encontrar cómo mostrar un año de 4 dígitos cuando se muestra un NSDate con un estilo de NSDateFormatterShortStyle. Por favor, avíseme si tiene una solución. Aquí está el código que estoy usando ahora.iphone shortdate con 4 dígitos año
[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease ];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
// add label for birth
UILabel *birthday = [[UILabel alloc] initWithFrame:CGRectMake(125, 10, 100, 25)];
birthday.textAlignment = UITextAlignmentRight;
birthday.tag = kLabelTag;
birthday.font = [UIFont boldSystemFontOfSize:14];
birthday.textColor = [UIColor grayColor];
birthday.text = [dateFormatter stringFromDate:p.Birth];
gracias pero necesito que localiza – Dave
para localizar, añada la línea dateFormatter.locale = [NSLocale autoupdatingCurrentLocale]; –
en realidad, también necesitará un cheque en caso de que el formato específico de la localidad ya sea aaaa, p. if ([formatString rangeOfString: @ "aaaa"]. location == NSNotFound) { NSString * fourDigitYearFormat = [[dateFormatter dateFormat] stringByReplacingOccurrencesOfString: @ "yy" withString: @ "yyyy"]; [dateFormatter setDateFormat: fourDigitYearFormat]; } –