Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 336
Bill F Avatar asked Sep 05 '15 17:09

Bill F


People also ask

How do you set a specific date in Java?

The setTime() method of Java Date class sets a date object. It sets date object to represent time milliseconds after January 1, 1970 00:00:00 GMT. Parameters: The function accepts a single parameter time which specifies the number of milliseconds. Return Value: It method has no return value.

How do you initialize a date object in Java?

Calendar to initialize date: Calendar calendar = Calendar. getInstance(); //To Initialize Date to current Date Date date = calendar. getTime(); //To Initialize Date to a specific Date of your choice (here I'm initializing the date to 2022-06-15) calendar.

How do you pass a date as a parameter in Java?

Using Date Class The pattern required by the user is specified while creating the SimpleDateFormat instance. The usage of format() method of the DateFormat class is made to pass the date object as a parameter to the method. DateFormat dform = new SimpleDateFormat( "dd/MM/yy HH:mm:ss" ); Date obj = new Date();


1 Answers

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();
like image 194
Knut Herrmann Avatar answered Oct 16 '22 07:10

Knut Herrmann