I am building an application where I need to convert The NSString to NSDate. I have googled and found a lot links of SOF mentioned below -
I had used the answer given there but the problem I still facing is explain below step by step.
I had taken NSString *StringDate = @"01:00:00"; // I have declared time in the NSString variable.
I used the conversion method that mentioned in above link and stored the converted value to the NSDate variable.
When I am NSLog the NSDate variable. I am get "19:30:00" in my logcat. While the expected result should be "01:00:00".
Here is one of the code I am using
NSString *dateString = @"01:00:00";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// this is imporant - we set our input date format to match our input string
// if format doesn't match you'll get nil from your string, so be careful
[dateFormatter setDateFormat:@"hh:mm:ss"];
NSDate *dateFromString = [[NSDate alloc] init];
// voila!
dateFromString = [dateFormatter dateFromString:dateString];