iPhone + Twitter API:转换时间? [英] iPhone + Twitter API: Converting time?

查看:90
本文介绍了iPhone + Twitter API:转换时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从现在开始,有没有一种简单的方法可以将从twitter获得的时间戳转换为unix时间或分钟?我可以解析字符串并自己转换所有内容,但我希望有一种方法可以转换,不需要。下面是带有时间戳的created_at元素的示例。

Is there an easy way to convert the time stamp you get from twitter into unix time or minutes since now? I could parse through the string and convert everything myself but I'm hoping there is a way to convert that doesn't need that. Here is an example of a created_at element with a time stamp.

Sun Mar 18 06:42:26 +0000 2007

Sun Mar 18 06:42:26 +0000 2007

推荐答案

您可以使用NSDateFormatter,如下所示:

You can use NSDateFormatter with something like this :


NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormatter setLocale:usLocale]; 
[usLocale release];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];

// see http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
[dateFormatter setDateFormat: @"EEE MMM dd HH:mm:ss Z yyyy"];

NSDate *date = [dateFormatter dateFromString:[currentDict objectForKey:@"created_at"]];
[dateFormatter release];

NSTimeInterval seconds = [date timeIntervalSince1970];

这篇关于iPhone + Twitter API:转换时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆