NSDateFormatterStyle.MediumStyle 未显示在 iPhone 中
NSDateFormatterStyle.MediumStyle doesn't show in iPhone
我在我的应用程序中使用 NSDateFormatterStyle.MediumStyle 来转换日期。我在标签上显示日期,字体大小为 12
它在
上运行
iPad
模拟器它显示像 "nov 12,1994" 但在我的
iPhone
设备显示短格式化程序:“11/12/1994”。
你知道为什么它在 iPad 上起作用但在 iPhone
上不起作用吗?
来自 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)
我在我的应用程序中使用 NSDateFormatterStyle.MediumStyle 来转换日期。我在标签上显示日期,字体大小为 12
它在
上运行iPad
模拟器它显示像 "nov 12,1994" 但在我的
iPhone
设备显示短格式化程序:“11/12/1994”。
你知道为什么它在 iPad 上起作用但在 iPhone
上不起作用吗?来自 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)