title: NSDateFormatter returns nil for date 13 Jan 2020 05:22:03 -0800
body: <p>I am trying to formate email dates but date formatter returns nil where last five characters -0800. Doesn't have any problem with date has +0000. I have list of mixed dates of emails ending with +0000 and -0800</p>
  
  <p>How can I add that 8 hours difference to my date to make it +0000? Some emails have sent from LA date origin as 13 Jan 2020 05:22:03 -0800. But, I am accessing in UK with 8 hours difference. </p>
  
  <p>13 Jan 2020 05:22:03 -0800 should look a like 13 Jan 2020 13:22:03 +0000</p>
  
  <pre><code>- (NSDate *) date
  {
      NSString *d = [headers objectForKey:@"date"];
      if (d == NULL)
          return NULL;
  
      NSRange rng = [d rangeOfString:@" ("];
      if (rng.location != NSNotFound)
          d = [d substringToIndex:rng.location];
  
      NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
      [formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"] autorelease]];
      formatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
      [formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZ"];
      NSDate *result = [formatter dateFromString:d];
      [formatter release];
  
      return result;
  }
  </code></pre>
  
  <p>13 Jan 2020 05:22:03 -0800 is the specific date returns nil. Any help is appriciated.</p>
  
  <p>I tried below statements</p>
  
  <pre><code>[formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];
  [formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
  [formatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"] autorelease]];
  [formatter setLocale:[[NSLocale currentLocale] autorelease]];
  
  [formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z"];
  [formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss zz"];
  [formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss zzzz"];
  
  [formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"];
  [formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZ"];
  [formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZZZ"];
  </code></pre>