我是 xcode 和面向对象开发的新手(当时是数据库......)并且我试图根据开始日期是否与结束日期相同来构建一个字符串,所以如果它是相同的返回开始日期,如果不返回开始和结束日期(即 15/02/2013 - 17/02/2013)。我的代码如下,但它不喜欢'fulldatestring',我的if语句有问题吗?
NSString *startDate = [info objectForKey:@"StartDate"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-mm-dd"];
NSDate *sdate = [dateFormatter dateFromString:startDate];
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/mm/yyyy"];
NSString *convertedStartDate = [dateFormatter stringFromDate:sdate];
NSString *endDate = [info objectForKey:@"EndDate"];
[dateFormatter setDateFormat:@"yyyy-mm-dd"];
NSDate *edate = [dateFormatter dateFromString:endDate];
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/mm/yyyy"];
NSString *convertedEndDate = [dateFormatter stringFromDate:edate];
if(convertedStartDate isEqualToString:convertedEndDate) {
NSString *fulldatestring = convertedStartDate;
}
else
NSString *fulldatestring = [convertedStartDate, convertedEndDate ];
{
cell.datesLabel.text = fulldatestring