title: iphone NSDate - get todays date and force the time
body: <p>hopefully a quick one for someone! I am struggling to see why the code below isn't working. I am trying to get today's date (eg: 2010-09-10) and manually adding the time. It always seems to return 00:00:00 for the time though. any ideas where I'm going wrong? </p>
  
  <pre><code>NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
  dateFormatter.dateFormat = @"yyyy-MM-dd";
  
  NSString *actualDate = [dateFormatter stringFromDate:[NSDate date]];
  NSDate *sDate = [dateFormatter dateFromString:[NSString stringWithFormat:@"%@ %@", actualDate, @"01:00:00"]];
  NSDate *eDate = [dateFormatter dateFromString:[NSString stringWithFormat:@"%@ %@", actualDate, @"23:59:59"]];
  </code></pre>
  
  <p>The NSDate objects are returning the format 2010-09-10 00:00:00 +01:00 all the time. Somewhere it's just not picking up the time.... any ideas? many thanks.</p>
  
  <p><strong>* UPDATE *</strong></p>
  
  <p>The code below works. I did as suggested and accessed the elements and updated them.</p>
  
  <pre><code>unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
      NSDate *date = [NSDate date];
      NSCalendar *calendar = [NSCalendar currentCalendar];
      NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
  
  NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
  dateFormatter.dateFormat = @"yyyy-MM-dd hh:mm:ss";
  
  //update for the start date
  [comps setHour:0];
  [comps setMinute:0];
  [comps setSecond:0];
  NSDate *sDate = [calendar dateFromComponents:comps];
  
  //update for the end date
  [comps setHour:23];
  [comps setMinute:59];
  [comps setSecond:59];
  NSDate *eDate = [calendar dateFromComponents:comps];
  </code></pre>