3 回答

TA贡献1853条经验 获得超18个赞
您应该使用HH:mm。
hh范围01-12,而HH范围1-23。
更新资料
检查文档的SimpleDateFormat:
H:一天中的小时(0-23)
h:上午/下午(1-12)

TA贡献1785条经验 获得超8个赞
String start = (String) startTime.getSelectedItem();
String end = (String) endTime.getSelectedItem();
SimpleDateFormat timer = new SimpleDateFormat("HH:mm");
try {
Date startD = timer.parse(start);
Date endD = timer.parse(end);
if(startD.before(endD)){
System.out.println("test1");// future date - good
}else{
System.out.println("fail2");// old date - bad
}
} catch (ParseException ex) {
System.out.println("error");
}
将我的代码更改为此解决了此问题。
添加回答
举报