13 Replies Latest reply: Dec 19, 2006 3:46 PM by 807607 RSS

    Converting Date.toString() back to a Date object for compare

    807607
      I know this is beating a dead horse to death but I have wasted a whole day trying to get this to work. Here is the problem.

      I need to convert a Date().toString (format returned: Dec 19, 2006 3:39:58 PM EST) back to a Date object. What I am doing is writting this string a text file and then revisiting it to compare later to a current Date object to find the difference in the two stamps in milliseconds.

      J2SE 1.4.2 being used
      Date date = new Date();
      String newDateStr = log[1].trim(); // entry from log file
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      Date logDate = dateFormat.parse(newDateStr);
      
      // get difference between the two
      long timeSpan = date.getTime() - logDate.getTime();
      if(timeSpan > 60000){
          // TO DO
      }
      So should I look at a different approach at either:
      A) Storing the date/time stamp in the text file
      B) The conversion back to Date object is wrong

      Really appreciate any insight on this.

      Thanks
      JLW

      Message was edited by:
      jlwestsr