Bill F
Bill F

Reputation: 2087

Set a Java date Object from a Notes DateTime Object

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.

Upvotes: 6

Views: 2736

Answers (1)

Knut Herrmann
Knut Herrmann

Reputation: 30960

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();

Upvotes: 12

Related Questions