我需要比较我输入的两个时间字符串..我能够为日期做,但是时间我无法做到。请在下面找到我尝试的代码:
我的要求是..当我将Lower
变量检查为"<<Current Time>>"
时,我需要获取系统的当前时间并与Upper
变量进行比较,该变量也有一个字符串时间..
Date T1 = new Date();
Date T2 = new Date();
String temp_Time = "",Upper="";
try{
DateFormat df = new SimpleDateFormat(format);
df.setLenient(false);
System.out.println("Gng to Parse");
String Lower = " <<Current Time>> ";
if(Lower.equalsIgnoreCase(" <<Current Time>> ")){
temp_Time = df.format(T1);
System.out.println("Formatted : "+temp_Time);
**//Here I get the time in format i specified.**
T1 = df.parse(temp_Time);
// **when i parse, the time format changes and prints "Thu Jan 01 13:24:40 IST 1970"**
System.out.println("T1 after parsed "+T1);
T2 = df.parse(Upper);
} else {
T1 = df.parse(Lower);
T2 = df.parse(Upper);
}
if (T1.after(T2) || T1.equals(T2)) {
System.out.println("Time after || equal");
System.out.println("Upper Time should be greater than Lower Date");
} else{
System.out.println("Else of after ");
}
}catch(ParseException p) {
System.out.println("Time Fields should be in mentioned format "+T1);
}
}