标签:
Android的文件有建议用Time代替Calendar。用Time对CPU的负荷会较小。在写Widget时特别重要。
Time t=new Time(); // or Time t=new Time("GMT+8"); 加上Time Zone资料。
唯一不足是取出时间只有24小时模式.
long time=System.currentTimeMillis();
final Calendar mCalendar=Calendar.getInstance();
mCalendar.setTimeInMillis(time);
取得小时:mHour=mCalendar.get(Calendar.HOUR);
取得分钟:mMinuts=mCalendar.get(Calendar.MINUTE);
如何获取Android系统时间是24小时制还是12小时制
ContentResolver cv = this.getContentResolver();
String strTimeFormat = android.provider.Settings.System.getString(cv,
android.provider.Settings.System.TIME_12_24);
if(strTimeFormat.equals("24"))
{
Log.i("activity","24");
}
Calendar c = Calendar.getInstance();
取得系统日期:year = c.get(Calendar.YEAR)
month = c.grt(Calendar.MONTH)
day = c.get(Calendar.DAY_OF_MONTH)
取得系统时间:hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE)
利用Calendar获取
Calendar c = Calendar.getInstance();
取得系统日期:year = c.get(Calendar.YEAR)
month = c.grt(Calendar.MONTH)
day = c.get(Calendar.DAY_OF_MONTH)
取得系统时间:hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE)
Calendar c = Calendar.getInstance();
取得系统日期:year = c.get(Calendar.YEAR)
month = c.grt(Calendar.MONTH)
day = c.get(Calendar.DAY_OF_MONTH)
取得系统时间:hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE)
标签:
原文地址:http://www.cnblogs.com/huangjianboke/p/5051230.html