iphone - Convert GMT NSDate to device's current Time Zone -
i'm using parse.com store values:
these gmt values. how convert these device's current time zone , nsdate result?
nsdate represented in gmt. it's how represent may change.
if want print date label.text
, convert string using nsdateformatter
, [nstimezone localtimezone]
, follows:
nsstring *gmtdatestring = @"08/12/2013 21:01"; nsdateformatter *df = [nsdateformatter new]; [df setdateformat:@"dd/mm/yyyy hh:mm"]; //create date assuming given string in gmt df.timezone = [nstimezone timezoneforsecondsfromgmt:0]; nsdate *date = [df datefromstring:gmtdatestring]; //create date string in local timezone df.timezone = [nstimezone timezoneforsecondsfromgmt:[nstimezone localtimezone].secondsfromgmt]; nsstring *localdatestring = [df stringfromdate:date]; nslog(@"date = %@", localdatestring); // local timezone is: europe/london (gmt+01:00) offset 3600 (daylight) // prints out: date = 08/12/2013 22:01
Comments
Post a Comment