Examples: DateRange class

  1. This example sets the StartDateTime and EndDateTime properties of a DateRange object through the createDateRange parameters, then displays the value of the Text property.
    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 dtdb = db.getCreated();
          DateTime dtnow = session.createDateTime("Today");
          dtnow.setNow();
          DateRange dr = session.createDateRange(dtdb, dtnow);
          System.out.println("Creation date - now:");
          System.out.println("  " + dr.getText());
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. This example sets the StartDateTime and EndDateTime properties of a DateRange object through the property methods, then displays the value of the Text property.
    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 dtdb = db.getCreated();
          DateTime dtnow = session.createDateTime("Today");
          dtnow.setNow();
          DateRange dr = session.createDateRange();
          dr.setStartDateTime(dtdb);
          dr.setEndDateTime(dtnow);
          System.out.println("Creation date - now:");
          System.out.println("  " + dr.getText());
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  3. This example writes a value to the Text property, then displays the LocalTime property of the StartDateTime and EndDateTime properties (which are DateTime objects).
    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 dtdb = db.getCreated();
          DateTime dtnow = session.createDateTime("Today");
          dtnow.setNow();
          DateRange dr = session.createDateRange();
          dr.setText
          (dtdb.getLocalTime() + " - " +
          dtnow.getLocalTime());
          System.out.println("Start date = " +
          dr.getStartDateTime().getLocalTime());
          System.out.println("End date = " +
          dr.getEndDateTime().getLocalTime());
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  4. This example sets a value for a DateRange object, then changes the DateTime object that the EndDateTime property is based on. This implicitly changes the EndDateTime property.
    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 dtdb = db.getCreated();
          DateTime dtplus = session.createDateTime("Today");
          dtplus.setNow();
          DateRange dr = session.createDateRange(dtdb, dtplus);
          dtplus.adjustMonth(2);
          System.out.println
          ("Creation date - 2 months from now:");
          System.out.println
          ("  " + dr.getText());
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }