我收到一个填充有数据的 json 对象,使用这些数据的任务之一是将时间组合在一起。
例如,如果GAME_TIME
是 12:15 PM,它应该在 12 PM 标题下。
我想出了一个解决方案,但它是一个怪物,并且很难调试,必须有更好的方法来做到这一点。
DbDate = DateFormatter.parse(json_data.getString("GAME_TIME"));
if (DbDate.compareTo(DateFormatter.parse("12:00 AM")) == 0 || DbDate.compareTo(DateFormatter.parse("1:00 AM") ) < 0) {
Users12AM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("1:00 AM")) == 0 || DbDate.compareTo(DateFormatter.parse("2:00 AM")) < 0) {
Users1AM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("2:00 AM")) == 0 || DbDate.compareTo(DateFormatter.parse("3:00 AM")) < 0) {
Users2AM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("3:00 AM")) == 0 || DbDate.compareTo(DateFormatter.parse("4:00 AM")) < 0) {
Users3AM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("4:00 AM")) == 0 || DbDate.compareTo(DateFormatter.parse("5:00 AM")) < 0) {
Users4AM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("5:00 AM")) == 0 || DbDate.compareTo(DateFormatter.parse("6:00 AM")) < 0) {
Users5AM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("6:00 AM")) == 0 || DbDate.compareTo(DateFormatter.parse("7:00 AM")) < 0) {
Users6AM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("7:00 AM")) == 0 || DbDate.compareTo(DateFormatter.parse("8:00 AM")) < 0) {
Users7AM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("8:00 AM")) == 0 || DbDate.compareTo(DateFormatter.parse("9:00 AM")) < 0) {
Users8AM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("9:00 AM")) == 0 || DbDate.compareTo(DateFormatter.parse("10:00 AM")) < 0) {
Users9AM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("10:00 AM")) == 0 || DbDate.compareTo(DateFormatter.parse("11:00 AM")) < 0) {
Users10AM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("11:00 PM")) == 0 || DbDate.compareTo(DateFormatter.parse("12:00 PM")) < 0) {
Users11AM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("12:00 PM")) == 0 || DbDate.compareTo(DateFormatter.parse("1:00 PM")) < 0) {
Users12PM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("1:00 PM")) == 0 || DbDate.compareTo(DateFormatter.parse("2:00 PM")) < 0) {
Users1PM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("2:00 PM")) == 0 || DbDate.compareTo(DateFormatter.parse("3:00 PM")) < 0) {
Users2PM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("3:00 PM")) == 0 || DbDate.compareTo(DateFormatter.parse("4:00 PM")) < 0) {
Users3PM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("4:00 PM")) == 0 || DbDate.compareTo(DateFormatter.parse("5:00 PM")) < 0) {
Users4PM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("5:00 PM")) == 0 || DbDate.compareTo(DateFormatter.parse("6:00 PM")) < 0) {
Users5PM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("6:00 PM")) == 0 || DbDate.compareTo(DateFormatter.parse("7:00 PM")) < 0) {
Users6PM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("7:00 PM")) == 0 || DbDate.compareTo(DateFormatter.parse("8:00 PM")) < 0) {
Users7PM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("8:00 PM")) == 0 || DbDate.compareTo(DateFormatter.parse("9:00 PM")) < 0) {
Users8PM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("9:00 PM")) == 0 || DbDate.compareTo(DateFormatter.parse("10:00 PM")) < 0) {
Users9PM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("10:00 PM")) == 0 || DbDate.compareTo(DateFormatter.parse("11:00 PM")) < 0) {
Users10PM.add(json_data.getString("IN_GAME_NAME"));
} else if (DbDate.compareTo(DateFormatter.parse("11:00 PM")) == 0 || DbDate.compareTo(DateFormatter.parse("12:00 PM")) < 0) {
Users11PM.add(json_data.getString("IN_GAME_NAME"));
}