NSDateFormatter Twitter JSON Api

发布于 2024-12-28 14:15:51 字数 474 浏览 4 评论 0原文

我正在尝试将 NSDate 格式化为 Twitter api (JSON) 给出的日期。因此我使用 NSDateFormatter 。

NSString *dateString = string;

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
//[dateFormat setDateFormat: @"EEE dd MMM yyyy HH:mm:ss Z"];
    NSDate *date = [dateFormat dateFromString:dateString]; 

    NSLog(@"%@",date);
    return date;

但是,这会返回 null。 Twitter API 给我的日期如下所示:2012 年 1 月 19 日星期四 07:04:51 +0000。

有人有解决这个问题的办法吗?

谢谢!

I'm trying to format an NSDate out of a date given by the Twitter api (JSON). I'm using a NSDateFormatter therefore.

NSString *dateString = string;

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
//[dateFormat setDateFormat: @"EEE dd MMM yyyy HH:mm:ss Z"];
    NSDate *date = [dateFormat dateFromString:dateString]; 

    NSLog(@"%@",date);
    return date;

But, this returns null. The date the Twitter API is giving me is looking like this: Thu, 19 Jan 2012 07:04:51 +0000.

Does anyone have a solution for this problem?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小兔几 2025-01-04 14:15:51

您错过了格式字符串中日期后面的逗号。正确:

[dateFormat setDateFormat: @"EEE, dd MMM yyyy HH:mm:ss Z"];

You missed the comma following the day in your format string. Correctly:

[dateFormat setDateFormat: @"EEE, dd MMM yyyy HH:mm:ss Z"];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文