Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting Adobe PDF date String to NSDate
    text
    copied!<p>The input string is '20100908041312'</p> <p>the format is year,month,day,Hours,minutes,seconds,time zone</p> <p>and I have ben trying to convert it to an NSDate with this: <code>@"yyyyMMddHHmmsszz"</code> </p> <p>But NSDate is nil, anyone see what I'm doing wrong?</p> <pre><code>-(NSDate*)convertPDFDateStringAsDate:(NSString*) _string{ //20100908041312 //year month day Hours minutes seconds and time zone NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyyMMddHHmmsszz"]; NSDate *date = [dateFormat dateFromString:_string]; //date is nil... [dateFormat release]; return date; } </code></pre> <p>EDIT: its the time zone breaking it</p> <p>EDIT2: <code>@"yyyyMMddHHmmssTZD"</code> stops it returning nil, but dosnt pick the time zone correctly</p> <p>EDIT3: This was the code I Used in the end...i found that the format changes from PDF to PDF so the code deals with the variations that i Found, in some cases this <strong>wont</strong> extract the Time Zone Properly.</p> <pre><code>-(NSDate*)convertPDFDateStringAsDate:(NSString*) _string{ NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; NSString * formatCheck = [_string substringToIndex:2]; if(![formatCheck isEqualToString:@"D:"]) { NSLog(@"ERROR: Date String wasnt in expected format"); return nil;//return [NSDate date]; } NSString * extract = [_string substringFromIndex:2]; //NSLog(@"DATESTRING:'%@'",extract);NSLog(@"DATELENGTH:%i",[extract length]); if([extract length]&gt;14) { [dateFormat setDateFormat:@"yyyyMMddHHmmssTZD"]; } else { [dateFormat setDateFormat:@"yyyyMMddHHmmss"]; } NSDate * date = [dateFormat dateFromString:extract]; [dateFormat release]; return date ; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload