温馨提示×

怎么将TextClock控件的时间显示为24小时制

小亿
295
2024-04-17 09:56:06
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

要将TextClock控件的时间显示为24小时制,可以通过设置TextClock控件的format12Hour和format24Hour属性来实现。

在XML布局文件中,可以设置TextClock控件的format24Hour属性为"kk:mm",表示使用24小时制的格式显示时间。

<TextClock
    android:id="@+id/textClock"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:format24Hour="kk:mm"
    />

在Java代码中,也可以通过调用setFormat24Hour()方法来设置TextClock控件的时间显示格式为24小时制。

TextClock textClock = findViewById(R.id.textClock);
textClock.setFormat24Hour("kk:mm");

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:Android时间控件怎么调整为24小时制

0