krishna Babu
krishna Babu

Reputation: 203

Returns NULL value

I get the null value when i print the log for sourceDate. it will give NULL value.

The code is:

NSMutableString * orignalStr = [[NSMutableString alloc] init];
[orignalStr appendString:date];
[orignalStr replaceOccurrencesOfString:@"T"
                            withString:@" "
                               options:NSCaseInsensitiveSearch
                                 range:NSMakeRange(0, 15)];
NSLog(@"The orignalString is =%@ ",orignalStr);

NSDateFormatter* dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss zzz "];

NSDate *sourceDate =[dateFormatter dateFromString:orignalStr];
NSLog(@"The sourceDate is =%@ ",sourceDate);

plz help me...

Upvotes: 0

Views: 132

Answers (1)

user756245
user756245

Reputation:

Try using this date format string : @"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", without replacing occurences of @"T".

EDIT after comment

You got a string like : "2011-07-19 GMT:10:00", the format string should be @"yyyy'-'MM'-'dd' GMT:'HH':'ss".

Upvotes: 1

Related Questions