ios - How to convert milliseconds to UTC time in Objective C? -
i getting milliseconds time backend guys. have convert utc time zone because can convert time zone easily. or there way change time according country out changing utc time zone.
i using code
nsdate *currentdate = mydate; double secsutc1970 = [currentdate timeintervalsince1970]; nsdate *date = [nsdate datewithtimeintervalsince1970:secsutc1970]; nsdateformatter *format = [[nsdateformatter alloc]init]; nstimezone *inputtimezone = [nstimezone timezonewithabbreviation:@"utc"]; [format settimezone:inputtimezone]; [format setdatestyle:nsdateformatterfullstyle]; [format settimestyle:nsdateformatterfullstyle]; nslog(@"%@",[format stringfromdate:date]); nstimezone *outputtimezone = [nstimezone localtimezone]; nsdateformatter *outputdateformatter = [[nsdateformatter alloc] init]; [outputdateformatter settimezone:outputtimezone]; [outputdateformatter setdatestyle:nsdateformatterfullstyle]; [outputdateformatter settimestyle:nsdateformatterfullstyle]; nsstring *outputstring = [outputdateformatter stringfromdate:date]; nslog(@"%@",outputstring);
my milliseconds 1468930910629 thanks
remember nsdate internally represented value relative utc date in past. having fixed reference point makes nsdate timezone independent, allowing compare nsdates nsdates without having worry timezones.
so, key thing else work create nsdates properly. see this or this examples.
Comments
Post a Comment