ios - NSDate Organization -
i'm attempting display timestamps in s, m, h format negative numbers on accounts of minutes format. better shown said:
the tweet chris supposed 4m , tweet mina supposed 6m. here implementation code:
// set timestamp nsdate *date = [nsdate datewithtimeintervalsince1970:[entry[@"created_time"] doublevalue]]; nsdate *currentdatentime = [nsdate date]; nscalendar *calendar = [nscalendar currentcalendar]; nsdatecomponents *instacomponents = [calendar components:(nscalendarunithour | nscalendarunitminute | nscalendarunitsecond) fromdate:date]; nsinteger instahour = [instacomponents hour]; nsinteger instaminute = [instacomponents minute]; nsinteger instasecond = [instacomponents second]; nsdatecomponents *realcomponents = [calendar components:(nscalendarunithour | nscalendarunitminute | nscalendarunitsecond) fromdate:currentdatentime]; nsinteger realhour = [realcomponents hour]; nsinteger realminute = [realcomponents minute]; nsinteger realsecond = [realcomponents second]; nsinteger hour = realhour - instahour; nsinteger minute = realminute - instaminute; nsinteger second = realsecond - instasecond; int adjustedseconds = ((int)minute * 60) - abs((int)second); int adjustedminutes = adjustedseconds / 60; if (hour==1 > minute > 0) { int negmin = ((int)hour * 60) - abs((int)minute); int posmin = abs(negmin); nsstring *strint = [nsstring stringwithformat:@"%dm",posmin]; cell.timeago.text = strint; }else if (hour>0){ nsstring *strint = [nsstring stringwithformat:@"%ldh",(long)hour]; cell.timeago.text = strint; }else if (hour==1){ nsstring *strint = [nsstring stringwithformat:@"%ldh",(long)hour]; cell.timeago.text = strint; }else if(minute == 1 > second){ nsstring *strint = [nsstring stringwithformat:@"%lds",(long)second]; cell.timeago.text = strint; }else{ nsstring *strfromint = [nsstring stringwithformat:@"%dm",adjustedminutes]; cell.timeago.text = strfromint; }
one main reason of happening timezone.
try set time zone gmt & after calculation. hope helps.
Comments
Post a Comment