I have an nsstring ,see below
NSString *Mydate=@\"9/8/2011\";
in month/day/year format.
I want this string to be in the format yyyy-M
Try below code with valid input string that will help you.
NSString *dateStr = @"9/8/2011 11:10:9";
NSDateFormatter *dtF = [[NSDateFormatter alloc] init];
[dtF setDateFormat:@"d/M/yyyy hh:mm:s"];
NSDate *d = [dtF dateFromString:dateStr];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd hh:mm:s"];
NSString *st = [dateFormat stringFromDate:d];
NSLog(@"%@",st);
[dtF release];
[dateFormat release];
You may use NSDateFormatter