需要特定日期格式的帮助 [英] Need help for specific date format

查看:110
本文介绍了需要特定日期格式的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个日期字符串

2011-08-30T11:44:54.345-04:00

帮助我撰写正确的格式来解析它与 dateFromString:

Help me to compose right format to parse it with dateFromString:

推荐答案

您需要删除最后一个冒号(时区,-04:00 - >-0400), Z 将采取类似-0800的方式,然后您可以尝试:

You need to eliminate the last colon (timezone, "-04:00" -> "-0400"), as Z will take something like "-0800", then you can give this a try:

NSString *dateString = @"2011-08-30T11:44:54.345-04:00";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-ddEHH:mm:ss.SSSZ"];
NSDate *date = [dateFormat dateFromString:dateString];
[dateFormat release];

有关日期格式的更多信息,请参阅此页面

For more information on date formatting, refer to this page.

这篇关于需要特定日期格式的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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