将字符串转换为日期Objective-C [英] Convert String to date Objective-C
本文介绍了将字符串转换为日期Objective-C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看到了其他答案和问题,但没有找到对我有用的答案。
我有一个像 2014-10-07T07:29:55.850Z
这样的字符串,我想有个日期进行比较。
如果我使用此代码:
I have seen the other answer and question but i didn't find any useful answer for me.
I have a string like 2014-10-07T07:29:55.850Z
and I want to have a date to compare each other.
If I use this code:
NSString *fullDate = payload[@"sent_ts"];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
dateFormat setDateFormat:@"yyyy-MM-ddTHH:mm:ss.SSSZ"];
NSDate *date = [dateFormat dateFromString:fullDate];
我的约会日期为零。为什么?
My date is nil. Why?
推荐答案
尝试一下。
NSString *dateString = @"2014-10-07T07:29:55.850Z";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
NSDate *date = [dateFormatter dateFromString:dateString];
这篇关于将字符串转换为日期Objective-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文