I have two String
variables:
time22
will store the time generated by Linux commandtimeInTheList
will store the time from myArrayList
time22
will get the most current time while the timeInTheList
will store some previous time.
I would like to compare both of these two times whether it have passed 30 minutes or not but I can't make it happen.
I found out some weird data printed out for the date, time and year and I only need the time, I will not need any date or year.
Code:
for(int x = 1;x<list1.size();x+=3)
{
try{
System.out.println("The time grab by linux command :"+time22);
String timeInTheList = list1.get(x);
System.out.println("The time in the balcklist.txt :" +timeInTheList);
SimpleDateFormat dateFormat1 = new SimpleDateFormat("HH:MM:SS");
Date Ftime1 = dateFormat1.parse(timeInTheList);
Date Stime2 = dateFormat1.parse(time22);
System.out.println("The Ftime1 value is :" +Ftime1);
System.out.println("The Stime2 value is :" +Stime2);
long diff1 = Stime2.getTime() - Ftime1.getTime();
System.out.println(Stime2.getTime());
System.out.println(Ftime1.getTime());
System.out.println("Difference between two time is :"+diff1);
if(diff1 > 1800)
{
System.out.println("it is more than 30 minute in the list");
String DeletedRule = list1.get(x+1).toString();
FinalDeletion(DeletedRule);
}
else
{
System.out.println("Keep in the list first,still not reach 30 minute");
}
}
catch(ParseException e)
{
e.printStackTrace();
}
}
This is the output from my program:
Time from linux command(In TimeIsNow Method) :22:02:50
The time grab by linux command :22:02:50
The time in the balcklist.txt :21:19:46
The Ftime1 value is :Thu Jul 01 21:00:00 MYT 1971
The Stime2 value is :Sun Feb 01 22:00:00 MYT 1970
2730600050
47223000046
Difference between two time is :-44492399996
Keep in the list first,still not reach 30 minute