string that looks like this: ThursDay November 27, 2008
First store the Date String into NSString then
The trick is two-fold, the date format string to specify desired output, and the method stringFromDate to convert the date object to an NSString.
Convert Another Formate of Date :-
The code below converts a string that represents a date to an NSString object, with the output as follows: Saturday November 22, 2008:
First store the Date String into NSString then
NSDate *date = [NSDate date]; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"EEEE MMMM d, YYYY"]; NSString *dateString = [dateFormat stringFromDate:date]; [dateFormat release]; |
Convert Another Formate of Date :-
The code below converts a string that represents a date to an NSString object, with the output as follows: Saturday November 22, 2008:
NSString *dateStr = @"20081122"; // Convert string to date object NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyyMMdd"]; NSDate *date = [dateFormat dateFromString:dateStr]; // Convert date object to desired output format [dateFormat setDateFormat:@"EEEE MMMM d, YYYY"]; dateStr = [dateFormat stringFromDate:date]; [dateFormat release]; |
No comments:
Post a Comment