Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6155079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:22:24+00:00 2026-05-23T20:22:24+00:00

I want convert string value into date in my project because I am fetching

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:22:25+00:00Added an answer on May 23, 2026 at 8:22 pm

    I gather that your problem is that future dates are coming in as "Thursday", "Friday", …?

    Basically, you need to convert that text to a day-of-week number (simplest approach is an "if ladder", though if you want to be locale-sensitive you can use a more complex scheme). Then figure out today’s day-of-week number and subtract that from the first number. If the result is negative, add 7. (If the result is zero, it may mean that it refers to today, or it may mean it refers to a week from today — if you want the latter, add 7 if the result is zero or negative.) Then, to compute the date represented by the input day of the week, add the above computed result multiplied times ONE_DAY to the current date.

    More detail

    You know what an "if ladder" is, of course:

    if ([day isEqualToString:@"Sunday"]) {
        dayNumber = 1;
    }
    else if ([day isEqualToString:@"Monday"]) {
        dayNumber = 2;
    }
    else if ([day isEqualToString:@"Tuesday"]) {
    ....
    

    To get the day of week from the current date use something like:

    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *components = [gregorian components:NSWeekdayCalendarUnit fromDate:today];
    NSInteger todayNumber = [components weekday];
    

    Subtract todayNumber from dayNumber. If the result is negative, add 7 to the result. That value then tells you how many days in the future "day" is, and from that you can calculate it’s date.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert a string into date time format. DateTime.Parse(tempfrmBankDetails.dgvBankDetails.SelectedRows[0].Cells[PaymentDate].Value.ToString(),null); This is
I want to convert a large 64 bit value from decimal or hex string
I want to convert a string into a double and after doing some math
I want to convert a string into a series of Keycodes, so that I
I have parsed .ics file and get the start date as string , the
i want to convert this string into DateTime. Tue Aug 19 15:05:05 +0000 2008
I want to convert a std::string to lowercase. I am aware of the function
I want to convert a primitive to a string, and I tried: myInt.toString(); This
I want to try to convert a string to a Guid, but I don't
I have a string, say '123' , and I want to convert it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.