问题
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.
回答1:
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();
来源:https://stackoverflow.com/questions/32415752/set-a-java-date-object-from-a-notes-datetime-object