I have a NSString which is passed from an xml feed……..
NSString *strDate =@"Thu, 22 Apr 2010 10.30 am CEST";
I’m currently using this code to format the date……..
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy hh:mm a vvvv"];
NSDate *myDate = [dateFormatter dateFromString:date];
[dateFormatter setDateFormat:@"HH"];
NSLog(@"%@", [dateFormatter stringFromDate:myDate]);
I want to format my string only to display only hours and currently I’m getting value like this.
strDate =@"2010-04-10 14:00:00 +0530";
Can anyone please help me with this?……
I’m sorry.It’s my mistake.It should be like this.
NSString *strDate =@"Thu, 22 Apr 2010 10:30 am CEST";
What my requirement is to get hour part only from above string using NSDateFormatter. How can I achieve that. Sorry for the earlier mistake.
Thanks.
If you want to get the 10 of 10:30 (if its ur requirement) then you can do it like:
and when you do:
Output : 10;
This is just a workaround, for better approach you should go through the NSDateComponents class.
Hope this helps.
Thanks,
Madhup