我想使用下面的代码在 TextView 中显示时间。
PersianCalendar persianCalendar = new PersianCalendar();
persianCalendar.setTime(mDate);
Calendar cal = Calendar.getInstance();
cal.setTime(mDate);
holder.tvTime.setText(cal.get(Calendar.HOUR_OF_DAY)+":"+cal.get(Calendar.MINUTE));
例如12:03
,当时间在 TextView 中显示为时会出现问题12:3
我怎样才能解决这个问题?
您可以将日期格式化为这样的字符串(使用 java.text.SimpleDateFormat)
holder.tvTime.setText(new SimpleDateFormat("H:mm").format(mDate));
该H
格式说明指小时在天(0-23),和mm
装置中的分钟数小时用两位数字。
有关其他格式选项,请参阅文档。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句