iphone - Issue in coverting GMT time to Local time -


my current device time --- 2013-05-09 10:23 am

i convert int gmt following code

   nsdateformatter *dateformatter = [[nsdateformatter alloc] init];    dateformatter.dateformat = @"yyyy-mm-dd hh:mm a";     nstimezone *gmt = [nstimezone timezonewithabbreviation:@"gmt"];   [dateformatter settimezone:gmt];    nsstring *timestamp = [dateformatter stringfromdate:[nsdate date]];    nslog(@"time in gmt ------ %@",timestamp); 

and got out put

     time in gmt ------  2013-05-10 04:53 

then found time zone

  nstimezone *localtime = [nstimezone systemtimezone];   nslog(@"local timezone  is------ %@",[localtime name]); 

out put

  local timezone  is------ asia/kolkata 

now need convert above gmt time local time.i used following code

   nstimezone* sourcetimezone = [nstimezone timezonewithabbreviation:[localtime name]];   [dateformatter settimezone:sourcetimezone];    nsdate *datefromstring = [dateformatter datefromstring:timestamp];    nslog(@"local time ------- %@",datefromstring); 

but getting wrong out put..

   local time ------- 2013-05-09 19:23:00 +0000 

why happen ? should local time - 2013-05-09 10:23 am

// current date/time

nsdate *today = [nsdate date]; nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; // display in 12hr/24hr (i.e. 11:25pm or 23:25) format according user settings [dateformatter settimestyle:nsdateformattershortstyle]; nsstring *currenttime = [dateformatter stringfromdate:today]; [dateformatter release]; nslog(@"user's current time in preference format:%@",currenttime); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -