Ios5 12月31日UIDatePicker发行

Ios5 12月31日UIDatePicker发行,ios5,nsdate,uidatepicker,Ios5,Nsdate,Uidatepicker,这似乎很奇怪。。。我正在操作表中使用UidatePicker。单击一个按钮,我将显示操作表。当我选择日期为2012年12月31日并单击“完成”时,我得到的日期是2013年12月31日。这件事一直在发生,而且只发生在12月31日。我做错什么了吗?这是我的密码 -(void)dateButtonPressed:(id)sender //Method invoking the action sheet on button press { actionSheet = [[UIActionSheet al

这似乎很奇怪。。。我正在操作表中使用UidatePicker。单击一个按钮,我将显示操作表。当我选择日期为2012年12月31日并单击“完成”时,我得到的日期是2013年12月31日。这件事一直在发生,而且只发生在12月31日。我做错什么了吗?这是我的密码

-(void)dateButtonPressed:(id)sender //Method invoking the action sheet on button press
{
actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];

CGRect pickerFrame = CGRectMake(0, 40, 0, 0);

closingdatePicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
closingdatePicker.tag=10;
closingdatePicker.datePickerMode=UIDatePickerModeDate;


pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle = UIBarStyleBlackTranslucent;
[pickerToolbar sizeToFit];

NSMutableArray *barItems = [[NSMutableArray alloc] init];

UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(DatePickerCancelClick:)];
[barItems addObject:cancelBtn];

UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];

UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(DatePickerDoneClick:)];
[barItems addObject:doneBtn];

[pickerToolbar setItems:barItems animated:YES];

[actionSheet addSubview:pickerToolbar];
[actionSheet addSubview:closingdatePicker];
[actionSheet showInView:self.view];
[closingdatePicker release];
[actionSheet setBounds:CGRectMake(0,0,320, 464)];
[actionSheet release];
}

- (void)DatePickerDoneClick:(id)sender{    //doen click and my date is stored in selectedDate
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/YYYY"];

//Gets our picker
UIDatePicker *ourDatePicker = (UIDatePicker *) [actionSheet viewWithTag:10];

NSDate *selectedDate = [ourDatePicker date];

closingDate.text=[NSString stringWithFormat:@"%@",[formatter stringFromDate:selectedDate]];

[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}

只需使用yyyy而不是yyy这在DateFormatter中有时会发生只需使用yyy而不是yyy这在DateFormatter中有时会发生有点晚,但您能解释一下为什么会发生在大写字母上吗?谢谢你的回答。虽然有点晚了,但是你能解释一下为什么它出现在大写字母上吗?谢谢你的回答。