Results 1 to 2 of 2
  1. #1
    sm123 is offline Member
    Join Date
    Mar 2010
    Posts
    11
    Rep Power
    0

    Default Creating a time sliding window..urgent

    Hi,

    My application continuously keeps on recieving files(call it "update" files).It reads a time field from a standard file(call it "master" file) which contains time in format hh:mm (13:35). There needs to be a sliding window of 60 mins before the time in "master" file.I need to check if the time at which these "update" files are recieved(i.e. current system time) comes within this sliding window. If yes only then I need to process the "update" files , else ignore. No question is how do I do this comparison of times?Please help

    Thanks,

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    I guess if you can parse the date string in the file into a date object
    Java Code:
    Date dateFromFile = new SimpleDateFormat("HH:mm").parse(strDate);
    then you could use the time expression of milliseconds to subtract the interval from the current time, and determine if the delta is over this threshold
    Java Code:
    long threshold = 60 * 60 * 1000; // 60 minutes
    Date timeNow = new Date();
    Date dateFromFile = new SimpleDateFormat("HH:mm").parse(strDate);
    long delta = timeNow.getTime() - dateFromFile.getTime();
    if (delta > threshold) {
      // the time difference is more than 60 minutes
    }
    else {
     // the time difference is less than or equal to 60 minutes.
    }

Similar Threads

  1. Creating Log In window
    By guru_boy in forum New To Java
    Replies: 2
    Last Post: 04-20-2009, 02:06 PM
  2. Replies: 2
    Last Post: 01-12-2009, 08:36 AM
  3. Replies: 0
    Last Post: 11-22-2008, 01:49 AM
  4. File creating date/time
    By bugger in forum New To Java
    Replies: 1
    Last Post: 11-11-2007, 07:43 PM
  5. Urgent-Imp-Displaying message with respect to system time
    By garinapavan in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 02:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •