字符串time1 =“09-00 AM”;字符串time2 =“07-00 PM”;
String date = 15-09-2017 04:04:33
parseInt()
如何比较time1和。之间存在的日期时间 时间2请建议我如何检查这个,我无法分割时间或与日期合并。
为此,我试图在HH中的Date对象中转换time1和time2:mm:SS
答案 0 :(得分:0)
使用.after
方法比较两个日期
查看此link了解更多详情
答案 1 :(得分:0)
public static void main(String[] args) {
try {
SimpleDateFormat df = new SimpleDateFormat("HH:mm a");
Date time1 = df.parse("09-00 AM");
Date time2 = df.parse("07-00 PM");
Date date = new Date();
SimpleDateFormat sf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
//converts date to required format
String current = sf.format(date);
Date currentTime = df.parse(current);
// TODO COMPARE currentTime with time1 or time2 as per your need
System.out.println(time1 + "" + time2 +" " + currentTime);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}