【发布时间】:2011-12-28 11:17:19
【问题描述】:
我有两个文本字段,如果我在第一个文本字段中输入日期...我应该在第二个字段中参考该日期获得恰好一周的日期。我在 NSDate 中搜索但无法获得它.
有什么建议
提前致谢:)
【问题讨论】:
标签: iphone ios xcode datepicker nsdate
我有两个文本字段,如果我在第一个文本字段中输入日期...我应该在第二个字段中参考该日期获得恰好一周的日期。我在 NSDate 中搜索但无法获得它.
有什么建议
提前致谢:)
【问题讨论】:
标签: iphone ios xcode datepicker nsdate
下面的代码可以帮助你:
NSDate *now = [NSDate date];
int daysToAdd = 50; // or 60 :-)
// set up date components
NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease];
[components setDay:daysToAdd];
// create a calendar
NSCalendar *gregorian = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
NSDate *newDate2 = [gregorian dateByAddingComponents:components toDate:now options:0];
NSLog(@"Clean: %@", newDate2);
//for displaying date in text field
txt.text = [NSString stringWithFormat:@"%@",newDate2];
【讨论】:
NSDate *newDate = [startDate dateByAddingTimeInterval:(86400 * 4)];
【讨论】: