2

i simple try to reformat a date:

 NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
 NSDate *date = [[NSData alloc] init];
 //Mon, 05 Apr 2010 14:27:48 -0700
 [formatter setDateFormat:@"E, dd MMM yyyy HH:mm:ss Z"];
 date = [formatter dateFromString:self.currentItemValue];        

 [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
 self.currentItem.pubDate = [formatter stringFromDate:date];
 [formatter release];

It works on the simulator, but on the device i only get (null).

Thanks for your help!

Some more tests:

NSString *string = @"Fri, 12 Dec 2008 18:45:15 -0800";
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss Z"];
NSDate *date = [dateFormatter dateFromString:string];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
//here i got (null) on the device but it works on simulator...
NSLog(@"date %@", [dateFormatter stringFromDate:date]);
phx
  • 1,509
  • 3
  • 15
  • 18
  • 1
    What region is the device set to? –  Apr 09 '10 at 15:06
  • I try something else.. i edited my question... – phx Apr 09 '10 at 16:55
  • 4
    On the device, under Settings, General, International, what is Region Format set to? If it's not an English region, you'll need to use setLocale method in date formatter and set it to en_US so it can parse the English day and month names in your input strings. See http://stackoverflow.com/questions/1559182/how-do-you-interpret-dates-with-nsdateformatter/1559284#1559284 for example. –  Apr 09 '10 at 17:50
  • My timezone is "Berlin", region Format is "German" – phx Apr 09 '10 at 17:50

1 Answers1

6

DyingCactus was right!

[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"] autorelease]];

solves my issue.... Thanks!!!!

Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
phx
  • 1,509
  • 3
  • 15
  • 18