iphone - NSDate is not transformed correctly -
i trying transform datestring format. doing this.
nslog(@"datestring %@",_dayobject.p_date); nsdateformatter *dateformat = [[nsdateformatter alloc] init]; [dateformat setdateformat:@"yyyy-mm-dd"]; nsdate *date = [dateformat datefromstring:_dayobject.p_date]; nslog(@"date transformed %@",date); [dateformat setdateformat:@"eeee, dd/mm/yyyy"]; [dateformat settimezone:[nstimezone timezonewithabbreviation:@"gmt"]]; nsstring *datestr = [dateformat stringfromdate:date]; nslog(@"datestring after %@",datestr);
but nslogs
2013-04-18 08:43:36.181 mosaqua2[9629:907] datestring 2013-05-04 2013-04-18 08:43:36.184 mosaqua2[9629:907] date transformed 2013-01-03 23:00:00 +0000 2013-04-18 08:43:36.184 mosaqua2[9629:907] datestring after donderdag, 03/01/2013
what want
saterday, 04/05/2013
can me ?
use bellow custom method convert date format ...
-(nsstring *)changedateformat:(nsstring*)stringdate dateformat:(nsstring*)dateformat getwithformat:(nsstring *)getwithformat{ nsdateformatter *dateformatter = [[[nsdateformatter alloc] init] autorelease]; [dateformatter setdateformat:dateformat]; nsdate *date = [dateformatter datefromstring:stringdate]; dateformatter = [[[nsdateformatter alloc] init] autorelease]; [dateformatter setdateformat:getwithformat]; nsstring *convertedstring = [dateformatter stringfromdate:date]; nslog(@"converted string : %@",convertedstring); return convertedstring; }
and use bellow...
nsstring *strsdate = [self changedateformat:_dayobject.p_date dateformat:@"yyyy-mm-dd" getwithformat:@"eeee, dd/mm/yyyy"]; nslog(@"datestring after %@",strsdate);
see my blog post...
Comments
Post a Comment