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 8925253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:38:44+00:00 2026-06-15T07:38:44+00:00

I am trying to split a NSDate I receive from web service into two

  • 0

I am trying to split a NSDate I receive from web service into two different dates in order to populate a tableView for events with sections for each day. I figured the least complicated way to do the latter is to create a fetch request looking for unique days.

So I try to create a NSDate “day” but having the time component set to 00:00. I wonder if there is a more efficient way to achieve this:

if (eventoItemList.count > 0) {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

        NSDateFormatter *dayFormatter = [[NSDateFormatter alloc] init];
        [dayFormatter setDateFormat:@"yyyy-MM-dd"];

        for (GDataXMLElement *eventoItem in eventoItemList) {
            BOEvent *event = [[BOEvent alloc] init];
            NSString *idEventStr = [[[eventoItem elementsForName:@"id"] objectAtIndex:0] stringValue];                       
            NSString *name = [[[eventoItem elementsForName:@"titulo"] objectAtIndex:0] stringValue];
            NSString *type = [[[eventoItem elementsForName:@"tipo"] objectAtIndex:0] stringValue];
            NSString *descr = [[[eventoItem elementsForName:@"descripcion"] objectAtIndex:0] stringValue];
            NSString *address = [[[eventoItem elementsForName:@"direccion"] objectAtIndex:0] stringValue];
            NSDate *date = [dateFormatter dateFromString:[[[eventoItem elementsForName:@"fecha"] objectAtIndex:0] stringValue]];
            NSString *action =  [[[eventoItem elementsForName:@"accion"] objectAtIndex:0] stringValue];

            [event setIdEvent:[idEventStr integerValue]];
            [event setName:name];
            [event setType:type];
            [event setDesc:descr];
            [event setAddress:address];
            [event setAction:action];
            [event setDate:date];
            [event setDayDate:[dayFormatter dateFromString:[dayFormatter stringFromDate:date]]];
            [events addObject:event];
        }
    }

Thank you for your help.

  • 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-06-15T07:38:45+00:00Added an answer on June 15, 2026 at 7:38 am

    sample code for splitting a NSDate into two NSDates (date only, time only)

         NSDate *date = [NSDate date];
        NSCalendar *gregorian = [NSCalendar currentCalendar];
    
        unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit;
        NSDateComponents *comps = [gregorian components:unitFlags fromDate:date];    
        NSDate *dateOnly = [gregorian dateFromComponents:comps];
    
        unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit |  NSDayCalendarUnit;
        comps = [gregorian components:unitFlags fromDate:date];    
        NSDate *timeOnly = [gregorian dateFromComponents:comps];
    
        NSLog(@"%@ = \n\tDate: %@ \n\tTime: %@", date, dateOnly, timeOnly);
    

    sample code for outputting NSDate in two NSStrings

        NSDate *date = [NSDate date];
    
        NSDateFormatter *f = [[NSDateFormatter alloc] init];
        [f setDateStyle:NSDateFormatterFullStyle];
        [f setTimeStyle:NSDateFormatterNoStyle];
        NSString *dateOnly = [f stringFromDate:date];
    
        [f setTimeStyle:NSDateFormatterFullStyle];
        [f setDateStyle:NSDateFormatterNoStyle];
        NSString *timeOnly = [f stringFromDate:date];
    
        NSLog(@"%@ = \n\tDate: %@ \n\tTime: %@", date, dateOnly, timeOnly);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to split up a web site into two sections. One which should
I'm trying to split up checkboxes in the same fieldset into two columns using
I am trying to split up an array (string1) of n characters into two
I'm trying to split an unordered list into two columns by finding the halfway
I'm trying to split a Maven WAR project into two modules, so that I
I'm trying to split a page into different shapes, as shown in this image:
Trying to split this string 主楼怎么走 into separate characters (I need an array) using
I am trying to split Scala list like List(1,2,3,4) into pairs (1,2) (2,3) (3,4)
I'm trying to split an app.config file into multiple files to make it easier
I'm trying to split a string into a int list for further processing. But

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.