How to convert the date string into string( yyyy-MM-dd). While doing so, I getting null values ?

Posted by Madan Mohan on Stack Overflow See other posts from Stack Overflow or by Madan Mohan
Published on 2010-04-30T06:33:15Z Indexed on 2010/04/30 6:37 UTC
Read the original article Hit count: 390

Filed under:
|
|

Hi,

I have the data as customerFromDate " 01 Apr 2010 " and customerToDate " 30 Apr 2010 " which is a string.

I want to convert that format into yyyy-MM-dd it should be in string. but while doing so. I got null values. Please see the following code which I had tried.

printf("\n customerFromDate %s",[customerStatementObj.customerFromDate UTF8String]); printf("\n customerToDate %s",[customerStatementObj.customerToDate UTF8String]); /* prints as the following customerFromDate 01 Apr 2010 customerToDate 30 Apr 2010 */

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate *fromDate=[[NSDate alloc]init];
fromDate = [dateFormatter dateFromString:customerStatementObj.customerFromDate];
printf("\n fromDate: %s",[fromDate.description UTF8String]);
NSString *fromDateString=[dateFormatter stringFromDate:fromDate];
printf("\n fromDateString: %s",[fromDateString UTF8String]);    
[dateFormatter release];

NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc]init];
[dateFormatter1 setDateFormat:@"yyyy-MM-dd"];
NSDate *toDate=[[NSDate alloc]init];
toDate = [dateFormatter1 dateFromString:customerStatementObj.customerToDate];
printf("\n toDate: %s",[toDate.description UTF8String]);
NSString *toDateString=[dateFormatter1 stringFromDate:toDate];
printf("\n toDateString: %s",[toDateString UTF8String]);            
[dateFormatter1 release];

Thank you, Madan Mohan.

© Stack Overflow or respective owner

Related posts about nsdate

Related posts about convert