cocoa - Formatting NSDates in the same timezone, regardless of the system timezone -


i'm importing number of references dates remote source. dates represent times of day on arbitrary day of year (in case 01/01/2000). supplied in unix timestamps. example 946717200 represents 9am. i'm getting timezone each location.

i'm using following code translate these times real dates correct offset utc.

-(nsdate *)datewithinterval:(nstimeinterval)interval referencedate:(nsdate *)arealdate timezone:(nstimezone *)atimezone {   nsdate *time = [nsdate datewithtimeintervalsince1970:interval];   nsdatecomponents *components = [[nsdatecomponents alloc] init];    //set timezone   [components settimezone:atimezone];    //i'm using erica sadun's nsdate+utilities category on nsdate provide shorthand methods   [components setday:[arealdate day]];   [components setmonth:[arealdate month]];   [components setyear:[arealdate year]];   [components sethour:[time hour]];   [components setminute:[time minute]];   [components setsecond:[time seconds]];    return [[nscalendar currentcalendar] datefromcomponents:components]; } 

for example given input of 946717200, current date, , america/los_angeles timezone, i'm given date 2013-10-07 16:00:00 +0000, when format using the nsdateformatter, timezone set america/los_angeles, , system set same timezone, appears 2013-10-07t01:00:00-0700

what not doing correctly?

the problem nsdate-utilities category. ignores timezone modifier of date , creates it's taking timezone in account. using own set of date components , setting timezone property issue went away.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -