xcode - iOS convert UTC string to local date -
code:
nsdateformatter *fmt = [[nsdateformatter alloc] init]; fmt.dateformat = @"yyyy-mm-dd hh:mm:ss"; nsdate *utc = [fmt datefromstring:strtime]; nstimezone *tz = [nstimezone defaulttimezone]; nsinteger seconds = [tz secondsfromgmtfordate: utc]; nsdate *localdate = [nsdate datewithtimeinterval:seconds sincedate:utc]; nsstring *local = [fmt stringfromdate:localdate]; nslog(@"local time%@", local); nsdate *localdate = [fmt datefromstring:local];
i getting utc string server. converted local string try convert local date. date showing in utc format.what wrong code?any appreciated.thanks in advance
try out:
nsdateformatter *fmt = [[nsdateformatter alloc] init]; fmt.dateformat = @"yyyy-mm-dd hh:mm:ss"; nsdate *utc = [fmt datefromstring:<your_utc_string>]; fmt.timezone = [nstimezone systemtimezone]; nsstring *local = [fmt stringfromdate:utc]; nslog(@"%@", local);
Comments
Post a Comment