Android数据格式化

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 time = (String)DateUtils.formatDateTime(this, System.currentTimeMillis(), flags_time);      
		//13:33
		boolean isToday = DateUtils.isToday(System.currentTimeMillis());                                   
		//true


Android数据格式化,布布扣,bubuko.com

Android数据格式化

上一篇:Be Happy.——我的ACM退役贴


下一篇:简单测试--C#实现中文汉字转拼音首字母