title: GMT to Local Time Conversion with Daylight Saving Time change
body: <p>From server I'm receiving GMT time structure(user defined structure), using that I want to convert it into local time, I have done it by filling the NSDatecomponent with the structure received, and then I have used date formattter to get date from it, everything works fine except one case. If the GMT time is after Nov 3 (<a href="https://en.wikipedia.org/wiki/Daylight_saving_time" rel="nofollow">Daylight Saving Time</a> change in US) formatter is producing 1 hour time difference.</p>
  
  <p>for eg: If the intended time is for Nov-3 ,4 PM, after conversion from GMT to local its giving Nov-3, 3 PM.</p>
  
  <p>Any idea how to avoid it.</p>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>   // Selected Dates
     NSDateComponents *sel_date = [[NSDateComponents alloc]init];
      sel_date.second = sch_detail.sel_dates.seconds;
      sel_date.minute = sch_detail.sel_dates.mins;
  
      sel_date.hour   = sch_detail.sel_dates.hours;
      sel_date.day    = sch_detail.sel_dates.date;
      sel_date.month  = sch_detail.sel_dates.month;
      sel_date.year   = sch_detail.sel_dates.year;
      sel_date.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
  
  
  
      // Get the Date format.
      NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
      [gregorian setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
  
      // Start_date formatter.
      NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
      [dateFormatter setDateFormat:@"MMM dd, yyyy hh:mm a"];
     [dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
  
     NSDate *strt_date_loc = [gregorian dateFromComponents:sel_date];
  
  
     // Get date string.
     NSString *sel_date_time = [dateFormatter stringFromDate: strt_date_loc];+
  </code></pre>
  
  <p>sel_date_time string is one hour less than what it supposed to be..</p>
  
  <p><strong>Log :</strong> </p>
  
  <p>strt_date_loc = 2013-11-30 06:56:00 +0000</p>
  
  <p>sel_date_time = Nov 29, 2013 10:56 PM (but it should be 11:56 PM)</p>
  
  <p>TimeZone : Palo Alto (US)</p>
  
  <p><strong>Local to gmt Conversion:</strong></p>
  
  <pre><code>- (NSDateComponents*) convert_to_gmt_time : (NSDate*) date
  {
      NSDate *localDate = date;
      NSTimeInterval timeZoneOffset = [[NSTimeZone defaultTimeZone] secondsFromGMT];
      NSTimeInterval gmtTimeInterval = [localDate timeIntervalSinceReferenceDate] - timeZoneOffset;
      NSDate *gmtDate = [NSDate dateWithTimeIntervalSinceReferenceDate:gmtTimeInterval];
  
      NSDateComponents *date_comp = [[NSCalendar currentCalendar] components: NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:gmtDate];
  
      return date_comp;
  }
  </code></pre>
  
  <p>thanx.</p>