根据当前日期可行的部分?

时间:2010-02-23 20:44:33

标签: iphone uitableview date

我希望用户在表格中输入一行......然后该行自动为其添加日期制作一个表格部分,并在白天按顺序保存。

也就是用户今天在表格中添加了一行...将它放在22日...明天他们将添加另一个单元格,将其添加到另一个部分feb 23,然后将行添加到其中

1 个答案:

答案 0 :(得分:0)

this will help...

today = [NSDate date];
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM/dd/yyyy :EEEE"];
dateString = [dateFormat stringFromDate:today];
NSLog(@"date: %@", dateString);
[dateFormat release];
gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
components = [gregorian components:NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:today];

[components setDay :( [components day] - ([components weekday] -2))];

NSDate *lastDayofweek = [gregorian dateFromComponents:components1];
NSDateFormatter *dateFormat_last = [[NSDateFormatter alloc] init];
[dateFormat_last setDateFormat:@"MMMM d,yyyy"];
NSString *dateString_last = [dateFormat_last stringFromDate:lastDayofweek];
[dateFormat_last autorelease];
NSDate *beginningOfWeek = [gregorian dateFromComponents:components];
NSDateFormatter *dateFormat_first = [[NSDateFormatter alloc] init];
[dateFormat_first setDateFormat:@"MMMM d,yyyy"];
NSString *dateString_first = [dateFormat_first stringFromDate:beginningOfWeek];
[dateFormat_first autorelease];