我需要找到一個Integer
week
其中配對Date
是距離當前時間戳最近的日期。執行與地圖值的比較
換句話說執行日期在matchMap
與之比較的值:
Map<Integer, Date> matchMap = null;
for (MatchSummary match : matchList) {
String str_date = match.getDate();
Date matchDate = null;
try {
matchDate = new SimpleDateFormat("yyyy-MMM-dd'T'HH:mm:ss.SSS'Z'" , Locale.getDefault()).parse(str_date);
} catch (java.text.ParseException e) { e.printStackTrace(); }
matchMap.put(match.getWeek(),matchDate);
}
下段找到最接近的日期爲當前時間戳:
final long now = System.currentTimeMillis();
Date closest = Collections.min(MAP_VALUE, new Comparator<Date>() {
public int compare(Date d1, Date d2) {
long diff1 = Math.abs(d1.getTime() - now);
long diff2 = Math.abs(d2.getTime() - now);
return Long.valueOf(diff1).compareTo(Long.valueOf(diff2));
}
);
應該是MAP_VALUE
PARAM什麼是能否達到目標?
'matchMap.values()'? – saka1029