菜鸟教程小白 发表于 2022-12-13 12:38:31

ios - NSDateFormatterStyle.MediumStyle 不显示在 iPhone


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

<p>它的功能在</p>

<blockquote>
<p>iPad</p>
</blockquote>

<p>模拟器显示像 <strong><em>"nov 12,1994"</em></strong> 但在我的</p>

<blockquote>
<p>iPhone</p>
</blockquote>

<p>显示短格式化程序的设备:<em>“11/12/1994”</em>。 </p>

<p>你知道为什么它可以在 iPad 上运行,但在 iPhone 上不行</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>来自 <code>NSDateFormatterStyle</code> 文档:</p>

<blockquote>
<p>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.</p>
</blockquote>

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

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

<pre><code>let date = NSDate()
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = &#34;MMM d, yyyy&#34;
dateFormatter.stringFromDate(date)
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - NSDateFormatterStyle.MediumStyle 不显示在 iPhone,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/34258762/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/34258762/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - NSDateFormatterStyle.MediumStyle 不显示在 iPhone