日期格式化程序不起作用?

Date Formatter not working?

我想将我的日期格式从 "MM/dd/YYYY HH:mm:ss" 更改为 "EEE dd MMM yyyy hh:mm a",但是我使用的代码不起作用,例如,如果我的输入是 11/30/2016T01:04:30 我是把月份改成12月,谁能帮忙看看错在哪里?

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);

不需要这个

// date = [date stringByReplacingOccurrencesOfString:@"T" withString:@" "];

像这样使用

 NSDateFormatter *df = [[NSDateFormatter alloc] init];
 NSString * date = @"11/30/2016T01:04:30";

[df setDateFormat:@"MM/dd/yyyy'T'HH:mm:ss"];
NSDate *myDate = [df dateFromString: date];

[df setDateFormat:@"EEE dd MMM yyyy hh:mm a"];
NSString *dayName= [df stringFromDate:myDate];
NSLog(@"the converted Day  %@",dayName);

输出:

the converted Day  Wed 30 Nov 2016 01:04 AM