title: iOS saving formatted datePicker strings
body: <p>Newbie here trying to modifying apples supplied 'Date Cell' sample code for learning purposes and am having real trouble with formatting dates. I have a tableView with three separate datePicker's in rows 1 (datePickerModeDateAndTime), row 2 (pickerModeDate), row 3 (pickerModeTime). Right now, I am just working on getting the value from the first picker (dateAndTime) logged so I can access it later. I have the selected date displayed in a detail of the tableView cell in the form 'Sep 20, 2013, 12:12 PM'. I am trying to get the value for the detail and write the difference between, 'NSDate date' and the selected time, to the app documents directory in the from of DD:HH:MM:SS remaining so that I can set a timer on another view that begins counting down to the selected date/time and displays the timer count in a UILabel. I have the log writing the date as '2013-09-20 18:12:33 +0000' when the picker is initially loaded to the screen but after the components change the log reads '0:00:00:-10'. So I have got it partially doing what I want but haven't been successful at getting the proper date out of it. thanks! </p>
  
  <pre><code>if(self.datePickerIndexPath.row == 1){
                  targetedDatePicker.datePickerMode = UIDatePickerModeDateAndTime;
                  self.dateFormatter = [[NSDateFormatter alloc] init];
                  [self.dateFormatter setDateStyle:NSDateFormatterMediumStyle];
                  [self.dateFormatter setTimeStyle:NSDateFormatterShortStyle];
  
                  NSDate *selected = [NSDate dateWithTimeIntervalSince1970:[self.pickerView.date timeIntervalSince1970] - 1];
                  self.deadlineCounter = [self.formatter stringFromDate:selected];
  
                  NSLog(@"selected is: %@", selected);
  
                  NSDate *todaysDate = [NSDate date];
  
                  NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
  
                  NSUInteger unitFlags = NSDayCalendarUnit | NSMinuteCalendarUnit | NSHourCalendarUnit | NSSecondCalendarUnit;
                  NSDateComponents *dateComparisonComponents = [gregorian components:unitFlags
                                                                            fromDate:todaysDate
                                                                              toDate:selected
                                                                             options:NSWrapCalendarComponents];
                  NSInteger days = [dateComparisonComponents day];
                  NSInteger hours = [dateComparisonComponents hour];
                  NSInteger minutes = [dateComparisonComponents minute];
                  NSInteger seconds = [dateComparisonComponents second];
  
                  self.DeadlineCounter = [NSString stringWithFormat:@"%ld:%02ld:%02ld:%02ld",
                                          (long)days,
                                          (long)hours,
                                          (long)minutes,
                                          (long)seconds];
                  NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
                  NSString *deadline = [NSString stringWithFormat:@"%@/deadline.txt", documentsDirectory];
                  NSInteger success = [NSKeyedArchiver archiveRootObject:selected toFile:deadline];
                  NSLog(@"success is: %d",success);
                  NSLog(@"deadline.txt was written successfully with these contents %@,", self.deadlineCounter);
  
                  targetedDatePicker.minimumDate = [NSDate date];
                  targetedDatePicker.maximumDate = [todaysDate dateByAddingTimeInterval:604800];
              }
  </code></pre>
  
  <p>Basically, if the user selects "Sep 25th, 2013, 2:25 PM" from the date picker, I want to write the string so that a countdown timer can be created, displayed in another view, and set to go off and the selected date and time. (I've gotten the date to be written and read on the correct controllers and the timerLabel displaying a date in the form "0:00:00:00", but it's the wrong numbers)</p>