Search code examples
javaxpageslotus-dominolotusdomino-designer-eclipse

Compare date-time in java agent(Lotus-domino designer) Xpages


I am writing a java agent in domino designer, the task is to compare current DateTime with the list of Date-Times which are in the document.I am able to retrieve the current date and the date-times from the documents,code for to get current date-time I have used

     Date date = new Date();
     DateTime current = session.createDateTime(date);
     System.out.println("Current Date-Time "+current);

code to get date time list from all the documents from the view is

          View dead_line = db.getView("deadline_date");
          ViewEntryCollection doc_collection = dead_line.getAllEntries();
          for(int i=1;i<count+1;i++){
          ViewEntry tempEntry = doc_collection.getNthEntry(i);
          Document deadline_date = tempEntry.getDocument();
          if(deadline_date.getItemValue("deadline_date")!=null && !deadline_date.getItemValue("deadline_date").isEmpty())
      {
          System.out.println("ALL Dead line dates "+deadline_date.getItemValue("deadline_date"));
      }

In console I am getting the dates properly. console output

Current Date-Time 30/06/2015 02:08:26 PM ZE5B

ALL Dead line dates [29/06/2015 01:00:00 PM ZE5B]
ALL Dead line dates [30/06/2015 07:50:00 AM ZE5B]

How do I can compare current date with retrieved date is equal or not,


Solution

  • DateTime class has a setAnyTime() method to ignore the time portion and a timeDifferenceDouble(DateTime) method to compare two DateTimes. Alternatively, DateTime has a toJavaDate() method to convert to a java.util.Date, which has comparison methods.

    OpenNTF Domino API extends the DateTime class to include equals(), equalsIgnoreTime() and (for completeness) equalsIgnoreDate() methods.