Examples: Working with time

  1. This agent gets the creation date of the current database into a DateTime object, prints the date-time in local time and GMT time, converts the time to zone 8 time, and prints the zone 8 time.
    import lotus.domino.*;
    public class JavaAgent extends AgentBase {
      public void NotesMain() {
        try {
          Session session = getSession();
          AgentContext agentContext = 
              session.getAgentContext();
          // (Your code goes here) 
          Database db = agentContext.getCurrentDatabase();
          DateTime dt = db.getCreated();
          System.out.println
          ("Creation date of current database");
          System.out.println
          ("  Local time: " + dt.getLocalTime());
          System.out.println
          ("  GMT time: " + dt.getGMTTime());
          boolean dst = dt.isDST();
          dt.convertToZone(8, dst);
          System.out.println
          ("  Time in zone 8: " + dt.getZoneTime());
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. This agent determines the earliest and latest creation dates for all the documents in the current database, and creates a DateRange object using these dates.
    import lotus.domino.*;
    public class JavaAgent extends AgentBase {
      public void NotesMain() {
        try {
          Session session = getSession();
          AgentContext agentContext = 
              session.getAgentContext();
          // (Your code goes here) 
          Database db = agentContext.getCurrentDatabase();
          DocumentCollection dc = db.getAllDocuments();
          Document doc = dc.getFirstDocument();
          if (doc == null) 
           System.out.println("No documents");
          else {
            DateTime dt1 = doc.getCreated();
            DateTime dt2 = doc.getCreated();
            doc = dc.getNextDocument(doc);
            while (doc != null) {
              // if dt1 > Created, Created -> dt1
              if (dt1.timeDifference(doc.getCreated()) > 0)
                dt1 = doc.getCreated();
              // if dt2 < Created, Created -> dt2
              if (dt2.timeDifference(doc.getCreated()) < 0)
                dt2 = doc.getCreated();
              doc = dc.getNextDocument(); }
            DateRange dr = 
                 session.createDateRange(dt1, dt2);
            System.out.println("Date range of documents:");
            System.out.println(dr.getText()); }
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }