3.15 如何使用TextClock以24小时格式显示时间

Posted on 2021-03-15 15:43  ***Pepsi***  阅读(387)  评论(0编辑  收藏  举报
我无法尝试以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.)

Copyright © 2024 ***Pepsi***
Powered by .NET 8.0 on Kubernetes