-2

Please how do I make my initWithFormat to display in as 8:00am - 2:30pm?

Help please!! I have already added "dd-MM-yyyy 'at' h:mm:ss a"

//opening
    NSString *startDate= ((Timeslot *)[self.timeslots objectAtIndex:i]).startDateTime;
    NSArray *split =[startDate componentsSeparatedByString: @"T"];
    NSString* clock =[split objectAtIndex: 1];
    NSArray *aux= [clock componentsSeparatedByString:@":"];
    NSString *startTime = [[NSString alloc] initWithFormat:@"%@:%@",[aux objectAtIndex:0],[aux objectAtIndex:1]];

    NSArray *st = [sttHour componentsSeparatedByString: @":"];
    if([[st objectAtIndex:0] integerValue] < [[aux objectAtIndex:0] integerValue])
    {
        if(![self.openings containsObject:startTime])
        {
            [self.openings addObject:startTime];
            [self.closings addObject:startTime];
        }

        [self.frees addObject:startTime];
    }

This is the value I am getting from the server:

Timeslot =  {
            endDateTime = "2014-07-25T16:00:00";
            id = 1344;
            startDateTime = "2014-07-25T14:00:00";
        };
senimii
  • 247
  • 2
  • 10
  • 1
    It's not a smart way. Use NSDateFormatter. – Ryan Jul 24 '14 at 08:45
  • I did that already and it was helpful until this I got stuck on this stage. – senimii Jul 24 '14 at 08:53
  • You clearly do not understand how date/time info is handled in iOS. Just fixing your code (if we could figure out how) will not make you understand this -- you've got to spend some time yourself, and in particular get over the mental blocks you have about how it *ought* to work. – Hot Licks Jul 24 '14 at 15:54
  • Further, you do not know how to ask a question here. The question for something like this should include ALL relevant code plus inputs plus outputs. And saying, eg, *I have already added "dd-MM-yyyy 'at' h:mm:ss a"* is useless when you don't tell us *where* you added that. – Hot Licks Jul 24 '14 at 15:56
  • Hint: If you're trying to read or write a formatted date, the date format string you use should look *a lot* like the date string you're trying to read/write. – Hot Licks Jul 24 '14 at 15:58
  • Duplicate of http://stackoverflow.com/questions/24914761/issues-with-stringwithformat – Hot Licks Jul 24 '14 at 17:28
  • Thank you @Hot Licks, this question was duplicated because I couldn't get help from the first time I submitted this. I have asked questions as it is with codes attached. I don't bother myself about the down voting. I am only worried that people that are in same dilemma as me wont want to take time to read what solution MIGHT be given in resolving this issue. I have read the documentation suggested and that has helped me in getting to this stage. Thank you still but your suggestion has not resolved this for me. – senimii Jul 24 '14 at 18:50
  • The thing is, you do not know how to write a proper question for Stack Overflow. You did not attach all the relevant code, nor did you provide good examples of input and output data. People look at your questions, see how muddled they are, and skip to the next question. You've asked 7 questions and only gotten one upvote. – Hot Licks Jul 24 '14 at 18:52

1 Answers1

1

Here's a Apple's documentation. You better read this first.

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html

Ryan
  • 4,799
  • 1
  • 29
  • 56