Besides the standard way of getting the current date as a String, one could come across the need of inserting in a database table column of date datatype. Thus, the well known code snippet won't be suitable:
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
java.util.Date date = new java.util.Date();
String datetime = dateFormat.format(date);
System.out.println("Current Date Time : " + datetime);
In case you use ADF business components for your Model project, you get the
current date in a slightly different way. Consider for example the following code snippet,
from an adf business components, employees entity object:
import oracle.jbo.domain.Date;
...
protected void doDML(int operation, TransactionEvent e) {
if (operation == DML_UPDATE) {
...
histStartDate = row.getEndDate();
/*Check whether end date equals current date*/
if (histStartDate.equals(new Date(Date.getCurrentDate()))){
System.out.println("End date equals current date!");
}
Finally, in case you prefer EJB's for your Model project instead, you might consider the following example:
/*Typical current date for DB inserts */
java.util.Date today = new java.util.Date();
java.sql.Date bidDate = new java.sql.Date(today.getTime());
/* public void setBidDate(Date bidDate)*/
newBid.setBidDate(bidDate);