0

I have problem converted a last modified HTTP date string like this

"Tue, 31 May 2016 22:13:38 GMT"

No matter what I try, I get back nil... Here's the code I am trying:

func ServiceConvertHTTPLastModifiedToNSDate(TmpStrDT: String) -> NSDate? {
  var TmpDTPtr: NSDate? = nil;
  //--
  //
  //--
  if TmpDTPtr == nil {
    TmpDTPtr = FDateFormatterHTTPResponseLastModfied1.dateFromString(TmpStrDT);
  }
  if TmpDTPtr == nil {
    TmpDTPtr = FDateFormatterHTTPResponseLastModfied2.dateFromString(TmpStrDT);
  }
  if TmpDTPtr == nil {
    TmpDTPtr = FDateFormatterHTTPResponseLastModfied3.dateFromString(TmpStrDT);
  }
  if TmpDTPtr == nil {
    TmpDTPtr = FDateFormatterHTTPResponseLastModfied4.dateFromString(TmpStrDT);
  }
  if TmpDTPtr == nil {
    TmpDTPtr = FDateFormatterHTTPResponseLastModfied5.dateFromString(TmpStrDT);
  }
  if TmpDTPtr == nil {
    TmpDTPtr = FDateFormatterHTTPResponseLastModfied6.dateFromString(TmpStrDT);
  }
  if TmpDTPtr == nil {
    TmpDTPtr = FDateFormatterHTTPResponseLastModfied7.dateFromString(TmpStrDT);
  }
  if TmpDTPtr == nil {
    TmpDTPtr = FDateFormatterHTTPResponseLastModfied8.dateFromString(TmpStrDT);
  }
  if TmpDTPtr == nil {
    TmpDTPtr = FDateFormatterHTTPResponseLastModfied9.dateFromString(TmpStrDT);
  }
  if TmpDTPtr == nil {
    TmpDTPtr = FDateFormatterHTTPResponseLastModfiedA.dateFromString(TmpStrDT);
  }
  if TmpDTPtr == nil {
    TmpDTPtr = FDateFormatterHTTPResponseLastModfiedB.dateFromString(TmpStrDT);
  }
  if TmpDTPtr == nil {
    TmpDTPtr = FDateFormatterHTTPResponseLastModfiedC.dateFromString(TmpStrDT);
  }
  //--
  //
  //--
  if TmpDTPtr == nil {
    msNoOp();
  }
  return TmpDTPtr;
}

where the date formatters are initialised like this:

FDateFormatterHTTPResponseLastModfied1.dateFormat = "EEEE, dd MMM yyyy hh:mm:ss zzz";
FDateFormatterHTTPResponseLastModfied2.dateFormat = "EEEE, dd MMM yyyy HH:mm:ss zzz";
FDateFormatterHTTPResponseLastModfied3.dateFormat = "EEE, dd MMM yyyy hh:mm:ss zzz";
FDateFormatterHTTPResponseLastModfied4.dateFormat = "EEE, dd MMM yyyy HH:mm:ss zzz";
//--
FDateFormatterHTTPResponseLastModfied5.dateFormat = "EEEE, dd LLL yyyy hh:mm:ss zzz";
FDateFormatterHTTPResponseLastModfied6.dateFormat = "EEEE, dd LLL yyyy HH:mm:ss zzz";
FDateFormatterHTTPResponseLastModfied7.dateFormat = "EEE, dd LLL yyyy hh:mm:ss zzz";
FDateFormatterHTTPResponseLastModfied8.dateFormat = "EEE, dd LLL yyyy HH:mm:ss zzz";
//--
FDateFormatterHTTPResponseLastModfied9.dateFormat = "EEEE, dd, LLL yyyy hh:mm:ss zzz";
FDateFormatterHTTPResponseLastModfiedA.dateFormat = "EEEE, dd, LLL yyyy HH:mm:ss zzz";
FDateFormatterHTTPResponseLastModfiedB.dateFormat = "EEE, dd, LLL yyyy hh:mm:ss zzz";
FDateFormatterHTTPResponseLastModfiedC.dateFormat = "EEE, dd, LLL yyyy HH:mm:ss zzz";

I have seen some use MMM and some use LLL, but I think all combinations are covered now....

The code is running on ios7 on an iphone4

Tom
  • 3,587
  • 9
  • 69
  • 124
  • Maybe this answer can help you (particularly the datetime format used): http://stackoverflow.com/questions/6253044/how-to-properly-convert-the-last-modified-header-from-an-http-response-to-an-nsd – Manuel Hoffmann Jun 02 '16 at 11:24
  • I am looking at every post I can find. I am completely mystified right now – Tom Jun 02 '16 at 11:46
  • I have extended the question, so it is easier to mass test different date formatters – Tom Jun 02 '16 at 12:41

0 Answers0