1. 程式人生 > >android得到系統時間如何判斷是白天還是晚上

android得到系統時間如何判斷是白天還是晚上

ContentResolver cv = getBaseContext().getContentResolver();
String strTimeFormat = android.provider.Settings.System.getString(cv, android.provider.Settings.System.TIME_12_24);
if(strTimeFormat!=null && strTimeFormat.equals("24"))
{
Log.i("Debug","24小時制");
}
else
{
String amPmValues;
Calendar c = Calendar.getInstance(); 
if(c.get(Calendar.AM_PM) == 0)
{
amPmValues = "AM";
}
else
{
amPmValues = "PM";
}
Log.i("Debug","12小時制現在是:" + amPmValues);
}