This discussion is archived
1 Reply Latest reply: Oct 24, 2013 3:05 PM by Gautam Singh RSS

how to compare the current system time with two timing?

eb20c2e9-ade7-43c7-8a85-f40499c1a389 Newbie
Currently Being Moderated

i want to get the current system time and compare with the two different timing example startwindow time as 2:00:00AM and endWindowTime as 6:00:00AM. if my current system time falls between these window i have to execute my rest of the code.

my below code works for fine for JAVA 1.6 version when i do the same code with JAVA 1.4 i am getting different date and time

String starTime=(String) NightlyvendorStatus[0].getPropertyValue("startTime");
 
String endTime=(String) NightlyvendorStatus[0].getPropertyValue("endTime");
 
Date windowStarttime = new SimpleDateFormat("HH:mm:ss").parse(starTime);
 
Date windowEndtime = new SimpleDateFormat("HH:mm:ss").parse(endTime);

 
Date systemdate = new Date();
 
SimpleDateFormat parser = new SimpleDateFormat("HH:mm:ss");
 
String systemTime=parser.format(systemdate);
 
Date currentTime = new SimpleDateFormat("HH:mm:ss").parse(systemTime);

 
if (currentTime.after(windowStarttime) && currentTime.before(windowEndtime))

{ --- rest of the logic here ---}

the output from JAVA 1.4 IS Thu Jan 01 02:00:00 GMT 1970 Thu Jan 01 06:00:00 GMT 1970 Thu Jan 01 03:23:00 GMT 1970

HOW TO DO this logic..

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points