dateformatter problem?

2019-03-06 11:23发布

I want to change the date formats. But i don't know how to give the input format

`Thu, 2 Dec 2010 00:28:56 -0500' i use the date formatter for user custom format

   NSString *inputString = @"Thu, 2 Dec 2010 00:28:56 -0500";
   NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
   [inputFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z"];

   NSDate *inputDate = [inputFormatter dateFromString:inputString];
   NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
   [outputFormatter setDateFormat:@"EEE. MMM. d, yyyy"];

   NSString *outputDate = [outputFormatter stringFromDate:inputDate];
   mylabel.text = outputDate;

but date not display

please give me the solution

1条回答
Fickle 薄情
2楼-- · 2019-03-06 11:49

The format string you showed us before you edited your question was correct. The only thing that was missing was that you need to set the date formatter's locale to English if you want it to recognize English month and day names:

[inputFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];
查看更多
登录 后发表回答