6

Manipulating Dates causing me some issues.

I've created some Java code that reads a document from a Notes DB then populates some fields in a Java Object with values from the Notes Document. The Notes Document contains a DataTime field "ExpPayDate" and I want to store it in the Java Object, but get a syntax error in the Java Editor. My code looks like this:

for (int n = 1 ; n < col.getCount(); n++){
    Document pDoc = col.getNthDocument(n);
    PaymentItem pItem = new PaymentItem();
    Date pDate = pDoc.getItemValue("ExpPayDate")[0];  
    pItem.setExpPayDate(pDate);
    .
    .
    .
    pDoc.recycle();     
} 

I have tried various ways to get the value from pDoc getItemValue getItemValueDateTime The above code gives a snytax error "the type od expression must bean array type but is resolved to Vector" if I remove the [0] the error is "type mismatch can not convert Vector to Date" I'm guessing that I'm missing something pretty simple but it has me stumped at the moment.

Bill F
  • 2,057
  • 3
  • 18
  • 39

1 Answers1

12

Use DateTime's .toJavaDate(). It converts Domino's DateTime value to Java's java.util.Date.

DateTime dateTime = (DateTime) pDoc.getItemValueDateTimeArray("ExpPayDate").get(0);
Date pDate = dateTime.toJavaDate();
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • And from there you can convert to `java.time.Instant` via `java.util.Date::toInstant` to avoid using the awful mess that is `Date`/`Calendar`. Those troublesome old legacy classes are now supplanted by the java.time classes. – Basil Bourque Apr 07 '17 at 07:52
  • Domino 9.0.1 is still on Java 1.6 but we are looking forward to Feature Pack 9 which will Support Java 1.8. Then we can use java.time.Instant too :) – Knut Herrmann Apr 07 '17 at 08:49
  • Much of the java.time functionality is back-ported to Java 6 and Java 7 in the [*ThreeTen-Backport*](http://www.threeten.org/threetenbp/) project by the same people. – Basil Bourque Apr 07 '17 at 08:52
  • i get the message toJavaDate() is undefined for the type DateTime – Malin Apr 12 '17 at 09:59
  • @Malin: It should be definied https://www.ibm.com/support/knowledgecenter/SSVRGU_9.0.1/basic/H_NOTESDATETIME_CLASS_JAVA.html . Is your import statement `import lotus.domino.DateTime;`? – Knut Herrmann Apr 12 '17 at 13:21