对于yyyy-MM-dd'T'HH的NSString到NSDate:mm:ss.SSS + 05:30格式 [英] NSString to NSDate for yyyy-MM-dd'T'HH:mm:ss.SSS+05:30 format

查看:130
本文介绍了对于yyyy-MM-dd'T'HH的NSString到NSDate:mm:ss.SSS + 05:30格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的日期字符串是2014-01-08T21:21:22.737 + 05:30这种格式。我如何将其授予NSDate?

My date string that I am getting is 2014-01-08T21:21:22.737+05:30 of this format. How do i confer it to NSDate?

我试过:

       NSString *currentDateString = @"2014-01-08T21:21:22.737+05:30";
       [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS+05:30"];
       NSDate *currentDate = [dateFormatter dateFromString:currentDateString];

       NSLog(@"CurrentDate:%@", currentDate);

它返回nil。有什么想法?

It returns nil. Any thoughts?

推荐答案

使用此代码它可以正常工作 dateFormatter 错了。

Use this code it is working fine your dateFormatter was wrong .

NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];

NSString *currentDateString = @"2014-01-08T21:21:22.737+05:30";
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZ"];        
NSDate *currentDate = [dateFormatter dateFromString:currentDateString];

NSLog(@"CurrentDate:%@", currentDate);

快乐编码!!!!!!!!!!。

Happy coding!!!!!!!!!!.

这篇关于对于yyyy-MM-dd'T'HH的NSString到NSDate:mm:ss.SSS + 05:30格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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