Reputation: 12333
i have a function to convert into NSDate
by using NSDateFormatter
.
+(NSDate*)getDateFromCurrentTimestamp:(NSString*)currentTimestamp{
// currentTimestamp= @"28-Feb-2012 16:42:19 PM";
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDoesRelativeDateFormatting:NO];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
[dateFormatter setFormatterBehavior:NSDateFormatterShortStyle];
//[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehaviorDefault];
[dateFormatter setDateFormat:@"dd-MMM-yyyy HH:mm:ss a"];
return [dateFormatter dateFromString:currentTimestamp];
}
IOS 5.x is returned correct NSDate
.
when run on 4.1 & 4.2 also returned correct NSDate
.
when run on 4.3.2 & 4.3.3, it's returned null
.
how is it possible? any workaround of this?
EDIT
This is not caused by iOS bug. this is related to phone itself. some phone has different locale
set in device. so we had to force it to use one locale
.
Upvotes: 2
Views: 863
Reputation: 7644
From our discussion in the comments:
Are your region and locale set for the 4.3.2 & 4.3.3 devices? See if this SO question helps.
Relevant code:
[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"] autorelease]];
Upvotes: 1
Reputation: 17317
It looks like someone ran into this issue before. A workaround is written up here: NSDateFormatter is returning null for date in ios 4.3.3
Upvotes: 1