How to convert a DD-MM-YYYY date format string into a YYYY-MM-DD date format string or into a NSDate object in Objective-C?

You can use NSDateFormatter to format a date in Objective C.

You can use NSDateFormatter to format a date in Objective C. Here's a quick example which might not do exactly what you want, but should hopefully give some pointers: // Convert my dd-mm-yyyyy string into a date object NSString *stringDate = @"01-02-2011"; NSDateFormatter *dateFormatter = NSDateFormatter alloc init; dateFormatter setDateFormat:@"dd-MM-yyyy"; NSDate *date = dateFormatter dateFromString:stringDate; // Convert my date object into yyyy-mm-dd string object dateFormatter setDateFormat:@"yyyy-MM-dd"; NSString *formattedStringDate = dateFormatter stringFromDate:date; dateFormatter release; Hope this helps! Nick.

– Csabi Feb 2 at 9:36 Good question! I've posted an update to my post. I've not tested this code, but hopefully it gives the idea!

Best of luck. N – Nick Cartwright Feb 2 at 9:41 NSDateFormatter *dateFormatter = NSDateFormatter alloc init; dateFormatter setDateFormat:@"dd-MM-yyyy"; NSDate *formattedDate = dateFormatter dateFromString:string; dateFormatter setDateFormat:@"yyyy-MM-dd"; NSString *elmentendo = dateFormatter stringFromDate:formattedDate; – Csabi Feb 2 at 9:42 like that it does not work :( M I missing something? – Csabi Feb 2 at 9:43 Are you sure your DD-MM-YYYY date is in the string variable?

– Douwe Maan Feb 2 at 9:45.

Using Nick's tutorial and answer the solution is : NSDateFormatter *dateFormatter = NSDateFormatter alloc init; dateFormatter setDateFormat:@"dd.MM. Yyyy"; NSDate *date = dateFormatter dateFromString:@"01.02.1989"; NSDateFormatter *dateFormatter1 = NSDateFormatter alloc init; // Convert my date object into yyyy-mm-dd string object dateFormatter1 setDateFormat:@"yyyy-MM-dd"; NSString *formattedStringDate = dateFormatter1 stringFromDate:date; dateFormatter release; dateFormatter1 release; NSLog(formattedStringDate); objektObrat. DateOfObrat = NSString alloc initWithString:formattedStringDate.

Great you found a solution to the problem & pleased to have helped! Good luck with the rest of your app. N – Nick Cartwright Feb 2 at 10:28.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions