OGeek|极客世界-中国程序员成长平台

标题: ios - NSDateFormatterStyle.MediumStyle 不显示在 iPhone [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 12:38
标题: ios - NSDateFormatterStyle.MediumStyle 不显示在 iPhone

我在我的应用程序中使用 NSDateFormatterStyle.MediumStyle 来转换日期。我在标签上显示日期,字体大小为 12

它的功能在

iPad

模拟器显示像 "nov 12,1994" 但在我的

iPhone

显示短格式化程序的设备:“11/12/1994”

你知道为什么它可以在 iPad 上运行,但在 iPhone 上不行



Best Answer-推荐答案


来自 NSDateFormatterStyle 文档:

The format for these date and time styles is not exact because they depend on the locale, user preference settings, and the operating system version. Do not use these constants if you want an exact format.

也就是说,我假设您的 iPad 和 iPhone 设置为不同的语言环境

如果您希望您的日期在所有语言环境中都与上面的 iPad 示例相同,您可以创建自己的格式化程序

let date = NSDate()
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MMM d, yyyy"
dateFormatter.stringFromDate(date)

关于ios - NSDateFormatterStyle.MediumStyle 不显示在 iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34258762/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4