gpt4 book ai didi

android - 如何使用 TextClock 以 24 小时格式显示时间?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:54:35 25 4
gpt4 key购买 nike

我在尝试以 24 小时格式显示时间时遇到问题。我已经让它显示另一个时区的时间,但我无法让它以 24 小时格式显示。

<TextClock
android:id="@+id/hk_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timeZone="GMT+0800"
android:format24Hour="MMM dd, yyyy k:mm" />

也可以使用 TextClock 显示日期吗?

最佳答案

如果您的系统处于 12 小时模式,您不必编写子类来获得您想要的东西。 JavaDocs说:

  • In 12-hour mode:
    • Use the value returned by getFormat12Hour() when non-null
    • Otherwise, use the value returned by getFormat24Hour() when non-null
    • Otherwise, use a default value appropriate for the user's locale, such as HH:mm

因此,我希望最后一行使 getFormat12Hour() 返回 null 并因此使用您自定义的 getFormat24Hour() 格式:

<android.widget.TextClock
android:id="@+id/hk_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timeZone="GMT+0800"
android:format24Hour="MMM dd, yyyy k:mm"
android:format12Hour="@null" />

(顺便说一句,正如其他人所提到的,强制格式应谨慎使用。如果您的用户想要 24 小时制,他们会在他们的系统首选项中指定这一点。以及强制使用数字格式、颠倒日期的应用程序他们的用户的格式,如 MM/dd/yyyy,邀请一星评级(除了,在这种情况下,来自美国和菲律宾用户),所以你使用 是件好事MMM!您最好还是使用 getBestDateTimePattern() ,不过,我相信这需要子类化 TextClock。)

关于android - 如何使用 TextClock 以 24 小时格式显示时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15367620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com