I have time in formate "02/17/2014 05:00 PM", now I want to convert it to 17-02-2014 05:00: 00 + 000. I am using the code. this date = 02/17/2014 and time = 5:00 p.m.
-(NSDate*)dateFromDate:(NSString*)date andTime:(NSString*)time{
NSString *eventDttm = [[NSString alloc] init];
eventDttm = [NSString stringWithFormat:@"%@ %@",date,time];
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
NSLocale *local = [NSLocale currentLocale];
[dateFormatter setLocale:local];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
[dateFormatter setDateFormat:@"dd-MM-yyyy HH:mm a"];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:eventDttm];
return dateFromString;
}
Using this code, I get 02/17/2014 11:00: 00 + 000
source
share