要让TextClock显示当前的日期和时间,可以通过设置TextClock的format属性来显示所需的日期和时间格式。例如,可以设置format为"yyyy-MM-dd HH:mm:ss"来显示当前的年月日时分秒。具体步骤如下:
<TextClock
android:id="@+id/textClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:format24Hour="yyyy-MM-dd HH:mm:ss"
android:format12Hour="yyyy-MM-dd hh:mm:ss a" />
TextClock textClock = findViewById(R.id.textClock);
textClock.setFormat12Hour("yyyy-MM-dd hh:mm:ss a");
textClock.setFormat24Hour("yyyy-MM-dd HH:mm:ss");
这样就可以让TextClock显示当前的日期和时间。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:js怎么显示当前日期和时间