现在的位置: 首页 > 综合 > 正文

android 显示时间格式24小时或12小时

2018年02月10日 ⁄ 综合 ⁄ 共 417字 ⁄ 字号 评论关闭
Time mTime = new Time();
 mTime.setToNow();

CharSequence mCharSequence;          

  String style = "";

            if (hour >= 0 && hour < 12) {
                style = "AM";
            } else if (hour >= 12) {
                style = "PM";
            }
            if (android.text.format.DateFormat.is24HourFormat(mContext)) {
                mCharSequence = DateFormat.format("kk:mm", mTime.toMillis(false));
            } else {
                mCharSequence = DateFormat.format("hh:mm", mTime.toMillis(false)) + " " + style;
            }

抱歉!评论已关闭.