NSString *lower = [NSString stringWithFormat:@"%@",[newDates objectAtIndex:0]];
NSString *higher = [NSString stringWithFormat:@"%@",[newDates objectAtIndex:[newDates count]-1]];
NSLog(@"%@",lower);
NSLog(@"%@",higher);
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd"];
NSDate *dtLower = [df dateFromString:lower];
NSDate *dtHigher = [df dateFromString:higher];
[df release];
NSDateFormatter *df1 = [[NSDateFormatter alloc] init];
[df1 setDateFormat:@"yyyy-MM-dd"];
NSString * lowerDate = [df1 stringFromDate:dtLower];
NSString * higherDate = [df1 stringFromDate:dtHigher];
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 31, self.view.frame.size.width, 30)];
[dateLabel setTextColor:[UIColor grayColor]];
dateLabel.text = [NSString stringWithFormat:@"%@ - %@",lowerDate,higherDate];
[self.view addSubview:dateLabel];
輸出的lower
和higher
在控制檯:- [NSDateFormatter dateFromString:]返回nil
2011-05-23 14:55:52.767 Vocab[4225:207] 2011-05-23 03:58:22
2011-05-23 14:55:53.781 Vocab[4225:207] 2011-05-23 07:14:56
在這裏,上面的代碼並沒有爲我工作。爲higher
和lower
值不爲空,但是當我嘗試使用NSDateFormatter轉換成NSDate的則返回零。
所以dtLower
和dtHigher
回零
出了什麼問題?
@parth:歡迎你:) – KingofBliss 2011-05-23 10:36:35