开发者

Calculate time span for facebook and twitter(Iphone development)

开发者 https://www.devze.com 2023-03-21 04:05 出处:网络
I开发者_StackOverflow中文版 want to calculate time span for twitter and facebook. For twitter:-Tue Jul 19 11:08:46 +0000 2011

I开发者_StackOverflow中文版 want to calculate time span for twitter and facebook.

For twitter:-Tue Jul 19 11:08:46 +0000 2011

for facebook:-2011-07-18T15:25:09+0000

I want to convert it in to like,1 hrs ago,60 min ago,2 mint ago etc.

And how to compare these time values for Time sorting.

Kindly Provide any sample code or Any class reference link,So that i can do that.


I am in the process of doing something similar.

I would first convert the time given by Twitter and Facebook into a NSDate using NSDateFormatter's setDateFormat function. Then you can compare by using NSDate's timeSinceNow function.

In the case of Twitter, it might look like this…

NSDateFormatter *dateFM = [[NSDateFormatter alloc] init];
[dateFM setDateFormat:@"EEE MMM dd HH:mm:ss ZZZZ yyyy"];  //set the format that matches Twitter's result…
[dateFM setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[dateFM setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
NSDate *twitterDate = [dateFM dateFromString:CTADateString];
float secondsOfTwitterDateSinceNow = [twitterDate timeIntervalSinceNow];

The result (secondsOfTwitterDateSinceNow) is the number of seconds elapsed since now which you can divide however you want (/60 = minutes, ect…)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号