开发者

dateformatter problem?

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";
   NSDateFo开发者_JS百科rmatter *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


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]];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜