android得到系统时间怎么判断是白天还是晚上。 做一个天气预报的程序。需要得到时间是白天还是晚上分别处理。但是得到的系统时间是十二小时制的,没有显示出白天还是晚上。即使我把手机改成二十四小时制的得到的时间也是十二小时制的。就像白天七点和晚上七点是分不出来的。而且还有一个问题就是,万一用户用的是十二小时制的话,那我也没法判断。大家帮帮忙有什么好的办法能判断是白天还是晚上。先谢谢大家了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以判断的,12小时制的时间里面的AM、PM分别代表上午、下午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); } 为什么会判断不了?你不需要理会用户的时间是12小时还是24小时,只要时间是正确的就行,SimpleDateFormat sdf = new SimpleDateFormat("HH");String hour= sdf.format(new Date()); 求助,广播Intent传递复杂数据类型 新手请教:代码哪里出错了? android listview 单双行背景效果 android 使用ksoap调用webservice 请问大家如何做APP的界面的?~谢谢指导 如何用android打开PPT文件,思路或者源码都可以 阅读器保存进度问题,请教 关于使用service的上下文和activity来读取sharedpreferences的同步问题 DrawerLayout主界面被导航界面覆盖 请问如何把Recyclerview嵌套进NavigationView当中? 29岁学安卓来的及吗? CDMA如何基站定位
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);
}
你不需要理会用户的时间是12小时还是24小时,只要时间是正确的就行,
SimpleDateFormat sdf = new SimpleDateFormat("HH");
String hour= sdf.format(new Date());