【发布时间】:2012-06-22 07:42:13
【问题描述】:
我有 2 个日期选择器,每个都遵循以太(280 天)
选择器更改正确,但mydatepicker.date NSlog 或将其放入UITextfield 日期变为日期 - 1 天或日期 + 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 输出是 11-12-2012
在我的代码中,我给了他们
的属性 lastPerPickerView.datePickerMode = UIDatePickerModeDate;
【问题讨论】:
标签: iphone xcode nsdateformatter uidatepicker nsdatecomponents