I am having time in formate "17-02-2014 05:00 PM",Now i want to convert it in 17-02-2014 05:00 :00 +000 .I am using code. in this date = 17-02-2014 and time = 05:00 PM
-(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"];
//conversion of NSString to NSDate
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:eventDttm];
return dateFromString;
}
Using this code i am getting 17-02-2014 11:00 :00 +000
you can use this code
NSString *str=@"17-02-2014 05:00 PM";
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"dd-MM-yyyy HH:mm a"];
NSDate *datetoday=[dateFormatter dateFromString:str];
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss Z"];
NSString *strdate=[dateFormatter stringFromDate:datetoday];
NSLog(@"%@",strdate);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With