I want to change my date format from "MM/dd/YYYY HH:mm:ss" to "EEE dd MMM yyyy hh:mm a", but the code I am using not working for example if my input is 11/30/2016T01:04:30 I am getting the month changed as December, can any one help where is the mistake?
NSString * date = @"11/30/2016T01:04:30";
date = [date stringByReplacingOccurrencesOfString:@"T" withString:@" "];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"MM/dd/YYYY HH:mm:ss"];
NSDate *myDate = [df dateFromString: date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE dd MMM yyyy hh:mm a"];
NSString *dayName= [dateFormatter stringFromDate:myDate];
NSLog(@"the converted Day %@",dayName);
YYYY
in first date Formate it should be smallyyyy
Also there is no need to use two dateFormatter you can work with single once and instead of replacingT
with space simply change your dateFormate toMM/dd/yyyy'T'HH:mm:ss
– Nirav D