public static void main(String[] args) {
String sys=DateUtil.getTime().substring(0,5);
System.out.println(sys);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
Calendar nowTime = Calendar.getInstance();
nowTime.add(Calendar.MINUTE, -10);
System.out.println(sdf.format(nowTime.getTime()));
SimpleDateFormat format = new SimpleDateFormat("HH:mm");
List<Map<String, Object>> alarmMaps = new ArrayList();
HashMap<String, Object> hashMap = new HashMap<>();
HashMap<String, Object> hashMap2 = new HashMap<>();
HashMap<String, Object> hashMap3 = new HashMap<>();
hashMap.put("TIME_NAME", "14:20");
hashMap.put("TIME_TYPE", "1");
hashMap2.put("TIME_NAME", "12:00");
hashMap2.put("TIME_TYPE", "1");
hashMap3.put("TIME_NAME", "9:00");
hashMap3.put("TIME_TYPE", "1");
alarmMaps.add(hashMap);
alarmMaps.add(hashMap2);
alarmMaps.add(hashMap3);
// 注:alarmMaps里面存在 count 属性
// String a="12:00";
// Integer valueOf = Integer.valueOf(a);
// System.out.println(valueOf);
//排序 倒序
if (alarmMaps != null && alarmMaps.size() > 1) {
Collections.sort(alarmMaps , new Comparator<Map<String, Object>>() {
@Override
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
Integer o1Value = Integer.valueOf(o1.get("TIME_NAME").toString().replace(":", ""));
Integer o2Value = Integer.valueOf(o2.get("TIME_NAME").toString().replace(":", ""));
return o1Value.compareTo(o2Value);
}
});
//14:00 <14:10-8
if (alarmMaps.get(alarmMaps.size()-1).get("TIME_NAME").toString().replace(":", "").compareTo(sdf.format(nowTime.getTime()).replace(":", ""))<0) {
alarmMaps.get(alarmMaps.size()-1).put("TIME_TYPE", "2");
// a.replace("1", "2");
}
}
for (Map<String, Object> map : alarmMaps) {
System.out.println(map.get("TIME_NAME"));
System.out.println(map.get("TIME_TYPE"));
}
}
//09:00@10:30@10:00@09:30
List<String> nums = new ArrayList<String>();
String a="09:00@10:30@10:00@09:30";
String[] timeArr=a.toString().split("@");
for(int i=0;i<timeArr.length;i++){
nums.add(String.valueOf(timeArr[i]));
}
Collections.sort(nums);
String[] timeArr2 = new String[nums.size()];
if (nums.size()>0) {
for (int i = 0; i < nums.size(); i++) {
timeArr2[i]=nums.get(i);
}
}
}