iphone - Convert GMT time to local time -
i got current gmt time - 2013-05-15 08:55 am
my current local time - 2013-05-15 02:06 pm , time zone - asia/kolkata
i tried convert above gmt local time code
nstimezone* sourcetimezone = [nstimezone timezonewithabbreviation:@"asia/kolkata"]; [dateformatter settimezone:sourcetimezone]; // timestamp - above gmt time nsdate *datefromstring = [dateformatter datefromstring:timestamp]; nslog(@"local time %@",datefromstring);
but give me wron time - 2013-05-14 19:04:00 +0000 instead of 2013-05-14 02:06 pm
why happens? please me clear this.thanks in advance
nothing going wrong, nsdate
instance never have timezone ( gmt, indicated +0000
timezone in date description).
what telling dateformatter in code timezone of date want parse asia/kolkata
want gmt
.
first need make nsdate
object input date string time zone set correct time zone, gmt
indicated.
nstimezone *gmttimezone = [nstimezone timezonewithabbreviation:@"gmt"]; [dateformatter settimezone:sourcetimezone]; nsdate *datefromstring = [dateformatter datefromstring:timestamp]; nslog(@"input date gmt: %@",datefromstring);
then when present date string use :
nstimezone* sourcetimezone = [nstimezone timezonewithname:@"asia/kolkata"]; [dateformatter settimezone:sourcetimezone]; nsstring *daterepresentation = [dateformatter stringfromdate:datefromstring]; nslog(@"date formated local time zone: %@",daterepresentation);
Comments
Post a Comment