I am geting below date from the server now I want to convert string to date.
Wed, 08 Jun 2011 11:58 pm EDT
But I cant success please give me advice. Thanks
I am geting below date from the server now I want to convert string to date.
Wed, 08 Jun 2011 11:58 pm EDT
But I cant success please give me advice. Thanks
In Objective-C, you commonly nead to convert a string to an NSDate
object. A simple way to do this is using the NSDateFormatter object. It provides the dateFromString method which converts a string into an NSDate object. You do, however, need to tell NSDateFormatter
the format the date will be in. See below example:
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss a"];
NSDate *myDate = [df dateFromString: myDateAsAStringValue];
And read about EDT – Eastern Daylight Time I think it would be better you change EDT to -0004.
ViTo basically answers this, but the precise format you're looking at for the string you are concerned with is:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE, dd MMM y hh:mm a zzz"];
NSLog(@"Date: %@", [dateFormatter dateFromString:@"Wed, 08 Jun 2011 11:58 pm EDT"]);
Take a look at the date format patterns. I add this because it wasn't immediately obvious where to find a description of the pattern.