I want convert string value into date in my project because I am fetching XML value from web. In XML file I get weather condition and there all value in this weather condition I get current date but my forecastcondition is not come in date it comes in string value, like this:
friday saturday and sunday
Like this value are come in my forecast condition day this string value come in Day_of_week [Day_of_week]
means it shows like this:
friday,saturday,sunday
How can I convert this string value with date?
This is my controller class.m file
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TWeatherCell *cell =(TWeatherCell *) [MyTableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"cell_%d", indexPath.row]];
if (cell == nil) {
//cell = [[[TWeatherCell alloc] initWithStyle:UITableViewStyleGrouped reuseIdentifier:CellIdentifier] autorelease];
cell = [[[TWeatherCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"cell_%d", indexPath.row]] autorelease];
}
//ForecastCondition *cond=[forecastcond objectAtIndex:0];
ForecastCondition *cond1=[forecastcond objectAtIndex:1];
ForecastCondition *cond2=[forecastcond objectAtIndex:2];
ForecastCondition *cond3=[forecastcond objectAtIndex:3];
NSDate *today = [NSDate date]; // some valid date, let's say today is thursdaya
NSDate *thursday = [today dateWithTimeInterval:1 *ONE_DAY sinceDate:cond1.Dayofweek];
NSDate *friday = [today dateWithTimeInterval:2 * ONE_DAY sinceDate:cond2.Dayofweek];
NSDate *saturday = [today dateWithTimeInterval:3 * ONE_DAY sinceDate:cond3.Dayofweek];
if ([currentcond.Icon isEqualToString:@"http://\n"])
{
cell.weatherimage.image = [UIImage imageNamed:@"listIcon-H.png"];
}
else {
NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:currentcond.Icon]];
NSLog(@"this is image from server:%@",imageData);
cell.weatherimage.image = [UIImage imageWithData:imageData];
[imageData release];
}
NSDateFormatter *date_formatter=[[NSDateFormatter alloc]init];
[date_formatter setDateFormat:@"dd-MM-yyyy"];
switch (indexPath.row) {
case 0:
NSLog(@"%d",indexPath.row);
NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:currentcond.Icon]];
NSLog(@"this is image from server:%@",imageData);
cell.weatherimage.image = [UIImage imageWithData:imageData];
[imageData release];
cell.reportdate.text = _forecastInfo.CurrentDateTime;
cell.conditionname.text = currentcond.Condition;
cell.twotemp.text = [NSString stringWithFormat:@"Temp:%@/%@",currentcond.Tempf,currentcond.Tempf];
cell.twodirection.text = currentcond.WindCondition;
cell.humidity.text = currentcond.Humidity;
break;
case 1:
NSLog(@"%d",indexPath.row);
cell.reportdate.text = cond1.Dayofweek;
cell.conditionname.text = cond1.Condition;
cell.twotemp.text = [NSString stringWithFormat:@"Temp:%@/%@",cond1.Low,cond1.High];
//NSDateFormatter *date_formatter=[[NSDateFormatter alloc]init];
// [date_formatter setDateFormat:@"dd-MM-yyyy"];
//[cond.Dayofweek dateWithTimeIntervalSinceNow:(60*60*24)*1];
//NSDate *date1 = [date_formatter dateFromString:cond.Dayofweek];
//NSDate *= NSDate *date1 ;
//NSDate *date1 = [NSDate date];
//NSString *strDate = [date_formatter stringFromDate:date1];
break;
case 2:
NSLog(@"%d",indexPath.row);
cell.reportdate.text = cond2.Dayofweek;
cell.conditionname.text = cond2.Condition;
cell.twotemp.text = [NSString stringWithFormat:@"Temp:%@/%@",cond2.Low,cond2.High];
break;
case 3:
NSLog(@"%d",indexPath.row);
cell.reportdate.text = cond3.Dayofweek;
cell.conditionname.text = cond3.Condition;
cell.twotemp.text = [NSString stringWithFormat:@"Temp:%@/%@",cond3.Low,cond3.High];
break;
default:
NSLog(@"Out of Range ",indexPath.row);
break;
}
return cell;
}