objective c - IOS system time is different when converting NSDateFormatter -


i setting datetime this

 nsdate* = [nsdate datewithtimeintervalsincenow:[[nstimezone systemtimezone] secondsfromgmt]]; 

and used value name 'now', trying convert nsstring this

    nsdate *date = [object valueforkey:@"datetime"];// valueforkey:@"datetime"=now     nslog(@"%@",date);     nsdateformatter *formatter = [[nsdateformatter alloc]init];       [formatter settimezone:[nstimezone systemtimezone]];     [formatter setdateformat:@"yyyy"];     nsstring *year = [formatter stringfromdate:date];     [formatter setlocale:[nslocale systemlocale]];     [formatter settimezone:[nstimezone systemtimezone]];     [formatter setdateformat:@"mm"];     nsstring *month = [formatter stringfromdate:date];     [formatter setlocale:[nslocale systemlocale]];     [formatter settimezone:[nstimezone systemtimezone]];     [formatter setdateformat:@"dd"];     nsstring *day = [formatter stringfromdate:date];     [formatter setlocale:[nslocale systemlocale]];     [formatter settimezone:[nstimezone systemtimezone]];     [formatter setdateformat:@"hh"];     nsstring *hour = [formatter stringfromdate:date];     [formatter setlocale:[nslocale systemlocale]];     [formatter settimezone:[nstimezone systemtimezone]];     [formatter setdateformat:@"mm"];     nsstring *minute = [formatter stringfromdate:date];     [formatter setlocale:[nslocale systemlocale]];     [formatter settimezone:[nstimezone systemtimezone]];     [formatter setdateformat:@"ss"];     nsstring *second = [formatter stringfromdate:date];  nslog(@"%@",date); nslog(@"%@/%@/%@ %@:%@:%@ ",year,month,day,hour,minute,second); 

consol log

2014-03-24 17:32:36.034 securitygate[7147:60b] 2014-03-24 15:51:29 +0000 2014-03-24 17:32:36.037 securitygate[7147:60b] 2014/03/25 00:51:29  

i want make same(system time japan.tokyo) please me.

your bug in line of code:

nsdate *date = [object valueforkey:@"datetime"];// valueforkey:@"datetime"=now 

the comment claims "now" it's not. nslog output is:

2014-03-24 17:32:36.034 securitygate[7147:60b] 2014-03-24 15:51:29 +0000 

notice @ start has time of nslog, presumably in local timezone (tokyo?).

but date printed totally different. hour explained timezone issues, minutes/seconds wrong. converting local timezone gives 2014-03-25 00:51:29, full 6 hours in future time i'm writing post.

so clearly, data inside object not "now" seem think.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -