views:

88

answers:

2

I know there are a lot of answers about that problem, but I need someone explain me easy, why on SDK 3.1.3 the code bellow returns the correct result, and in the same code in IOS4 return nil. Thanks a lot for any suggestion.
Marcello

 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; 
 [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
 NSDate *testOut = [dateFormatter dateFromString:[itemAtIndex objectForKey:@"data"]];

 NSDateFormatter *df = [[NSDateFormatter alloc] init];
 df.dateStyle = NSDateFormatterShortStyle;
 NSString *pippo = [NSString stringWithFormat:@"%@  >",[df stringFromDate:testOut]];

5/6/2010

Hi, I tried to solve with this code by following your information:

NSString *myDate = [NSDateFormatter localizedStringFromDate:[itemAtIndex objectForKey:@"data"] dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterShortStyle NS_AVAILABLE(10_6, 4_0)];

but I get only invalid CFStringRef...

It is just a little bit frustrating Have you any suggestion.. Thanks for your time.. Marcello

+1  A: 

Not quite sure what I was thinking..my old answer doesn't make any sense.

I just tested the code you have pasted in iOS 4.0 and it works fine.

What part of this code is returning nil?

Joshua Weinberg
A: 

The problem was in the [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"], the right command is "yyyy-MM-dd HH:mm:ss ZZZZ". Intact, if I understood it correct, the time in SQLITE format is with + 01:00 at the end of the string, to indicate the local time from the Greenwich time. It drive me crazy.... It's a strong thing because since the 3.1.3 sdk the code worked fine. This answer is for the people like me....

p.s. For Joshua, I didn't receive your reply trough the notify e-mail, but I like to tell you how I resolved my question and give you thanks for spent your time for my question. Ciao Marcello

mballic