NSDateFormatter在设备和模拟器上给出不同的值?什么是工作? [英] NSDateFormatter gives different values on device and simulator? What is work around?

查看:108
本文介绍了NSDateFormatter在设备和模拟器上给出不同的值?什么是工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用NSDateFormatter,问题是它的一致性。如果我使用kCFDateFormatterMediumStyle,它在模拟器中的格式为2009年11月26日,但在设备上它给出2009年11月26日。

I am using NSDateFormatter, the problem is with its consistency. If I use the kCFDateFormatterMediumStyle it gives the format as "Nov 26, 2009" in simulator but on device it gives "26-Nov-2009".

问题,这是NSFormatter可信意味着在不久的将来或更新从苹果可以改变风格了吗?

Now I have the question, Is this NSFormatter trustable means in near future or updates from apple can it change the style again?

推荐答案

NSDateFormatter根据设备上的国际设置,将日期格式化为用户的首选项。因此,你不能期望这个字符串是一致的,因为日期在世界各地显示的不同方式的数量。

NSDateFormatter formats the date to the user's preference, based on the International settings on the device. As such you can never expect this string to be consistent because of the amount of different ways that dates are displayed across the world.

我找到了最好的格式作为字符串的日期(用于给予web服务器等)是使用NSDateComponents并将它们转换为字符串。

I've found the best way to format a date as a string (to use to give to webservers etc) is to use NSDateComponents and convert these to strings.

这篇关于NSDateFormatter在设备和模拟器上给出不同的值?什么是工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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