I have a string like "20121124T103000
" and I want to convert this to NSDate
.
I tried converting it with dateFormatter date format "yyyyMMddThhmmss
" but it gives output as 2001-01-01 00:00:00 +0000
which is incorrect.
What is the way we can convert this string to NSDate
?
Here is my code:
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyyMMddThhmmss"];
NSLog(@"%@",[dateFormat dateFromString:@"20121124T103000"]);
Any help is appreciated.
do like this,
Your original code is quite close; instead of:
You should be using:
The only difference is the pair of single quotes around the 'T' in the string- you just need to let the app know that 'T' is a part of the formatting, not the actual date.
Try the following Code.