iphone - Problem in getting time -



iphone - Problem in getting time -

hi need increment 15 minutes in time intrval in webservice . code follows

nsstring *datestring =obj.string_date_start; // start time 2011-07-01 datestring = [datestring stringbyappendingstring:[nsstring stringwithformat:@" %@ +0000",obj.string_time_start]]; //after statement date 2011-07-01 03:00:00 +0000 nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; [dateformatter setdateformat:@"yyyy-mm-dd hh:mm:ss z"]; nsdate *datefromstring = [[nsdate alloc] init]; datefromstring = [dateformatter datefromstring:datestring]; nsdate *scheduledforyellow = [datefromstring datebyaddingtimeinterval:900]; [dateformatter release]; nsdateformatter *dateformatter1 = [[nsdateformatter alloc] init]; [dateformatter1 setdateformat:@"yyyy-mm-dd hh:mm:ss z"]; nsstring *strtime = [dateformatter1 stringfromdate:scheduledforyellow]; [dateformatter1 release]; nsarray *aryy = [strtime componentsseparatedbystring:@" "]; nslog(@"end time ======>>>%@",[aryy objectatindex:1]); obj.string_staticendtime = [aryy objectatindex:1];

here add together 15 minutes start time have written above code , in end time [aryy objectatindex:1] not give me right time.what wanted increment 15 minutes whatever date in start date .dont know whats issue is.

`

it must because of default timezone (local timezone) date formatter uses generate string. have modified code bit reuse date formatter , fixed leak datefromstring.

nsstring *datestring = obj.string_date_start; // start time 2011-07-01 datestring = [datestring stringbyappendingstring:[nsstring stringwithformat:@" %@ +0000",obj.string_time_start]]; //after statement date 2011-07-01 03:00:00 +0000 nsdateformatter *dateformatter = [[[nsdateformatter alloc] init] autorelease]; [dateformatter setdateformat:@"yyyy-mm-dd hh:mm:ss z"]; nsdate * datefromstring = [dateformatter datefromstring:datestring]; nsdate * scheduledforyellow = [datefromstring datebyaddingtimeinterval:900]; [dateformatter settimezone:[nstimezone timezonewithname:@"gmt"]]; nsstring * strtime = [dateformatter datefromstring:scheduledforyellow]; nsarray * aryy = [strtime componentsseparatedbystring:@" "]; nslog(@"end time ======>>>%@",[aryy objectatindex:1]); obj.string_staticendtime = [aryy objectatindex:1];

this should prepare issue. allow me know if face issues.

iphone objective-c nsdate nsdatecomponents

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -