ios - CST timezone add one day from november 3rd in iphone? -
i tried add 1 day november 3rd timezone dallas, can't it.
nsdate *intime = @"2013-11-03 05:00:00 +0000"; nsdate *nextday= [nsdate datewithtimeinterval:24*3600 sincedate:intime]; nsdateformatter *formatter=[[nsdateformatter alloc]init]; [formatter setdateformat:@"mm/dd/yyyy"]; nsstring *convert=[formatter stringfromdate:nextday]; nslog(@"convert:%@",convert); nslog values:
intime: 2013-11-03 05:00:00 +0000 nextday: 2013-11-04 05:00:00 +0000 convert: 11/03/2013 23:00:00 // need 11/04/2013. please let me know, how that,
thanks in advance
the problem intime - have use formatter initialize nsdate string. tested example be:
// nsdate *intime = @"2013-11-03 05:00:00 +0000"; // wrong nsstring *str =@"2013-11-03 05:00:00 +0000"; nsdateformatter *formatter = [[nsdateformatter alloc]init]; [formatter setdateformat:@"yyyy-mm-dd hh:mm:ss zzz"]; nsdate *intime = [formatter datefromstring:str]; nsdate *nextday= [nsdate datewithtimeinterval:24*3600 sincedate:intime]; nsdateformatter *formatter2=[[nsdateformatter alloc]init]; [formatter2 setdateformat:@"mm/dd/yyyy"]; nsstring *convert=[formatter2 stringfromdate:nextday]; nslog(@"%@, %@, %@", intime, nextday, convert); the output is:
2013-08-08 15:03:23.762 2013-11-03 05:00:00 +0000, 2013-11-04 05:00:00 +0000, 11/04/2013
one small comment: default xcode writes out these kind of problems code when showing issues switched on (preferences->general->show live issues). eg. in case xcode warns issue: incompatible pointer types initializing 'nsdate *__strong' expression of type 'nsstring *'
Comments
Post a Comment