iphone – dateFromString返回nil

前端之家收集整理的这篇文章主要介绍了iphone – dateFromString返回nil前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的NSString,

myDate : 2011-06-07 11:23:47  0000

这是代码,

NSTimeZone *currentDateTimeZone = [NSTimeZone defaultTimeZone];
NSDateFormatter *currentDateFormat = [[NSDateFormatter alloc]init];
[currentDateFormat setTimeZone:currentDateTimeZone];
[currentDateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
NSDate *tempDate = [currentDateFormat dateFromString:second];

仍然tempDate得到的值为零.
有人可以帮忙吗?

解决方法

你是怎么得到日期字符串的?它需要在2011-06-07 11:23:47 0000才能发挥作用.

猜你在找的Xcode相关文章