NSDateFormatter dateFromString:stringDate在iOS 8.3中返回nil [英] NSDateFormatter dateFromString:stringDate returning nil in iOS 8.3

查看:144
本文介绍了NSDateFormatter dateFromString:stringDate在iOS 8.3中返回nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码

NSString *stringDate = @"2015-07-09 7:00 AM";
NSString *stringDateFormat = @"yyyy-MM-dd h:mm a";
NSTimeZone *timeZone =  [NSTimeZone localTimeZone];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter setTimeZone:timeZone];
[dateFormatter setDateFormat:stringDateFormat];
NSDate *dateFormatted = [dateFormatter dateFromString:stringDate];

现在的问题是 dateFormatted 不断获得零值.当我在模拟器iPhone5s 8.2中尝试它时可以,但是,当我在设备iPhone5s 8.3中运行它时,会出现问题.

The problem now is dateFormatted keeps getting nil value. It is OK when I try it in Simulator iPhone5s 8.2 but, the problem occurs when I run it with device iPhone5s 8.3.

有人可以帮我找出为什么 dateFormatted 的价值为零吗?

Can someone help me find why is dateFormatted is getting nil value?

推荐答案

这几乎是罐头答复,但是:

It's almost a canned response but: QA1480. Set your formatter's locale to en_US_POSIX or its behaviour will be dependent upon the user's settings.

这篇关于NSDateFormatter dateFromString:stringDate在iOS 8.3中返回nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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