tags:

views:

137

answers:

2

I have parsed .ics file and get the start date as string , the string contains value like this 20100803T130451Z (this is formated date string), I want to convert this string into my required string format ....

My required format of date string is (Tuesday - May 25,2010 (like this))

Can anyone help me? Thanks in advance.....

+1  A: 
  1. Create a NSDateFormatter to convert the date string to a NSDate object.
  2. Create a second NSDateFormatter (or change the format string of the first) to convert the NSDate back to a string.
Ole Begemann
+1  A: 

Hi there

Ole is right, here some sample code.

This:

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyyMMdd'T'HHmmss'Z'"];
NSDate* date = [dateFormatter dateFromString:dateString];

should do the conversion of the NSString to a NSDate. To then get your desired date format you can change the NSDateFormatters dateFormat. Like this:

[dateFormatter setDateFormat:@"dddd - MMMM dd,yyy"];
NSString* myNiceLookingDate = [dateFormatter stringFromDate:date];
[dateFormatter release];

That should work, although I did not test it but it will get you at least closer to the result.

have fun, phil.

dreipol
This code only works in 3.2 not work in iphone sim 4.0.Any ideas ?
dragon
yes, you are right - tested it: It seems like the dateFormatter is a little bit more sensitive in iOS 4. Setting the dateFormat the following way: [dateFormatter setDateFormat:@"yyyyMMdd'T'HHmmss'Z'"]; should fix your problem. I corrected it in the post.
dreipol
Thanks . its worked fine
dragon