Friday, January 14, 2011

DateTime.toJavaDate() issue

Lotus Notes DateTime.toJavaDate() function sets time part to curren time if it was avoided in the DateTime Object. So each time you call toJavaDate() on such object you will receive different time. For example
"15.01.2011" -> "15.01.2011 15:36:37"
"15.01.2011" -> "15.01.2011 15:36:41"
and so on. Code for fix this:

4 comments:

Pete Clifford said...
This comment has been removed by the author.
Stuart Orford said...

Agh! Thanks for this, I spent hours this morning working out why I couldn't get two dates to be equal.

Stuart Orford said...

Actually, a small change - I think you want:

jCalendar.set(Calendar.HOUR_OF_DAY, 0);

Andy Conn said...

This was a helpful but in my case the time being set was the current time LESS GMT adjustment (in my case 5 hours GMT-5 EST). This creates a problem if the current time is shortly after midnight. The toJavaTime() is being adjusted minus 5 hours to the PRIOR DAY.

I found this solution accounts for all scenarios:

notesDateTime.setLocalTime(notesDateTime.getDateOnly() + " 00:00:00");
Date javaResult = notesDateTime.toJavaDate();