我有2個日期選擇器,每一個從以太(280天) 順利改變,但mydatepicker.date
當NSlog或將它放在UITextfield
之日起開始日期 - 1天或日期+1天UIDatePicker,在UITextView中用作字符串時的+/- 1天差異
這裏是我的代碼:
第一選擇器:
int daysToAdd = -280;
// set up date components
NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
[components setDay:daysToAdd];
// create a calendar
NSCalendar *addingdays = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDate *newDate = [addingdays dateByAddingComponents:components toDate:dueDatePickerView.date options:0];
lastPerPickerView.date = newDate;
NSLog(@"%@",newDate);
第二個:
int daysToAdd2 = 280;
// set up date components
NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
[components setDay:daysToAdd2];
// create a calendar
NSCalendar *addingdays2 = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDate *newDate2 = [addingdays2 dateByAddingComponents:components toDate:lastPerPickerView.date options:0];
dueDatePickerView.date = newDate2;
NSLog(@"%@",newDate2);
如果第一個選擇器的日期是12-12-2012 的出來說就是二零一二年十一月十二日
在我的代碼我給他們的
lastPerPickerView.datePickerMode = UIDatePickerModeDate;
不工作! – Mutawe