Swift iOS:对于某些设备,无法从字符串中解析日期.太奇怪了 [英] Swift iOS: Parsing of date from a string does not work for some devices. so weird

查看:79
本文介绍了Swift iOS:对于某些设备,无法从字符串中解析日期.太奇怪了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调试器中,它显示日期字符串为"2017-08-01 00:00:00",我也传递了正确的格式.但是dateFormatter.date部分对于1台设备总是失败(返回nil).但有些适用于模拟器和其他iphone设备. 我正在使用swift3

From the debugger it shows that the date string is "2017-08-01 00:00:00" and I passed the correct format too. But the dateFormatter.date part always fail (return nil) for 1 device. But some its working for simulator and other iphone devices. Im using swift3

推荐答案

尝试设置您的语言环境:

Try to set your locale:

dateFormatter.locale = Locale(identifier: "en_US_POSIX")

这篇关于Swift iOS:对于某些设备,无法从字符串中解析日期.太奇怪了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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