TextClock 格式控制统一

下面所有的地方都用了format12Hour和format24Hour是为了忽略系统时间格式,不管系统是12小时制还是24小时制,都能正常显示时间

转载:

Android TextClock时间格式 - 简书

TextClock 这个控件的使用. 

动态代码:

if (!TextUtils.isEmpty(strTimeFormat) && strTimeFormat.equals("24")) {
    views.setCharSequence(R.id.textclock, "setFormat24Hour", "HH:mm");
} else {
    views.setCharSequence(R.id.textclock, "setFormat12Hour", "HH:mm");
}

静态布局:

<TextClock
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:format12Hour="yyyy年MM月dd日  EEEE  aa  HH:mm:ss"
        android:format24Hour="yyyy年MM月dd日  EEEE  aa  HH:mm:ss" />

猜你喜欢

转载自blog.csdn.net/yanxiangxue/article/details/121427576