Sri
Sri

Reputation: 454

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

Upvotes: 0

Views: 227

Answers (1)

Ole Begemann
Ole Begemann

Reputation: 135540

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

Upvotes: 1

Related Questions