Thank for your replies. I googled about the problem and somewhere I found that NSDate has a bug in iOS 4.1. So I solved the problem using following method
- (NSString *)formattedStringUsingFormat:(NSString *)dateFormat
{
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:dateFormat];
[formatter setCalendar:cal];
[formatter setLocale:[NSLocale currentLocale]];
NSString *ret = [formatter stringFromDate:[NSDate date]];
[formatter release];
[cal release];
return ret;
}
and I passed the format as
[self formattedStringUsingFormat:@"yyyy-MM-dd HH:mm:ss ZZ"];