Convert date in MM/dd/yyyy format in xcode? Convert date in MM/dd/yyyy format in xcode? ios ios

Convert date in MM/dd/yyyy format in xcode?


See Instruction or introduction with every line

NSString *str = @"2012-10-30"; /// here this is your date with format yyyy-MM-ddNSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; // here we create NSDateFormatter object for change the Format of date..[dateFormatter setDateFormat:@"yyyy-MM-dd"]; //// here set format of date which is in your output date (means above str with format)NSDate *date = [dateFormatter dateFromString: str]; // here you can fetch date from string with define formatdateFormatter = [[[NSDateFormatter alloc] init] autorelease];[dateFormatter setDateFormat:@"dd/MM/yyyy"];// here set format which you want...NSString *convertedString = [dateFormatter stringFromDate:date]; //here convert date in NSStringNSLog(@"Converted String : %@",convertedString);


NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];[formatter setDateFormat:@"MM/dd/yyyy"];