1、文件大小格式化:
Log.d(TAG, Formatter.formatFileSize(this, 100)); //100 B Log.d(TAG, Formatter.formatFileSize(this, 1024*2)); //2.00 KB Log.d(TAG, Formatter.formatFileSize(this, 10000000)); //9.54 MB
2、日期格式化:
int flagsDate = DateUtils.FORMAT_SHOW_DATE; int flagsTime = DateUtils.FORMAT_SHOW_TIME ; int flagsWeek = DateUtils.FORMAT_SHOW_WEEKDAY; int flags_time = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_24HOUR; String dateStr = (String)DateUtils.formatDateTime(this, System.currentTimeMillis(), flagsDate); //7月8日 String timeStr = (String)DateUtils.formatDateTime(this, System.currentTimeMillis(), flagsTime); //下午1:33 String weekStr = (String)DateUtils.formatDateTime(this, System.currentTimeMillis(), flagsWeek); //星期二 String amPmStr = DateUtils.getAMPMString(Calendar.getInstance().get(Calendar.AM_PM)); //下午 String datetime = DateFormat.format("yyyy:MM:dd kk:mm:ss", System.currentTimeMillis()).toString(); //2014:07:08 13:33:23 String datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis())); //2014:07:08 13:33:23 String time = (String)DateUtils.formatDateTime(this, System.currentTimeMillis(), flags_time); //13:33 boolean isToday = DateUtils.isToday(System.currentTimeMillis()); //true
3、时间格式化
String.format("%d:%02d:%02d", hours, minutes, seconds).toString();