我有两个字符串变量- time1和time2。两者都包含HH:MM.格式的值。如何检查:
time1和time2?内time1会在最近的一小时发生吗?Upd. --我已经实现了以下将time1转换为Date格式的方法。但它使用的是折旧方法:
Date clTime1 = new Date();
SimpleDateFormat timeParser = new SimpleDateFormat("HH:mm", Locale.US);
try {
clTime1 = timeParser.parse(time1);
} catch (ParseException e) {
}
Calendar now = Calendar.getInstance();
clTime1.setYear(now.get(Calendar.YEAR) - 1900);
clTime1.setMonth(now.get(Calendar.MONTH));
clTime1.setDate(now.get(Calendar.DAY_OF_MONTH));
System.out.println(clTime1.toString());https://stackoverflow.com/questions/6377278
复制相似问题