iphone - why date gets changed when i try to change formate? -


this question exact duplicate of:

this code using changing date formate

      nslog(@"newbirthdates%@",_newwbirthdates);     nsdateformatter *form = [[nsdateformatter alloc] init];     [form setdateformat:@"mm/dd"];     nsdate *date1 =[nsdate date];     nsstring *string =[form stringfromdate:date1];      nslog(@"string%@",string);     nsdate *todaydate =[form datefromstring:string];      nslog(@"todaydate%@",todaydate); 

this output

     newbirthdates(     "05/22",     "07/11",     "10/07",     "02/20" )  newbirthdates(     "05/22",     "07/11",     "10/07",     "02/20" )  string03/18  todaydate1970-03-17 18:30:00 +0000 

now question why 3/18 become 03/17?? why 1 day decreases

the answer simple - time zones. take close @ nslog prints out
1970-03-17 18:30:00 +0000

by default, nsdateformatter set local timezone. means, if time zone +5:30 giving date "1970/18/3" results in 1970-03-18 00:00:00 +0530. however, nslog prints dates in gmt (zero) time zone, adding/substracting time zone difference (5 hours , 30 minutes).

basically, there nothing fix, have understand how nslog works if want use check nsdate values.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -