Jul 27, 2012

Convert sysdate to jbo.domain.Date

We can convert current date to oracle.jbo.domain.Date using  java.sql.Date and java.util.Date.

For this we have to take current date in a String variable.

  1.  DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
  2.  java.util.Date date = new java.util.Date();
  3.  String date1=dateFormat.format(date);

Now change this String date1 to java.util.Date.
As we cannot change date1 to oracle.jbo.domain.Date directly because oracle.jbo.domain.Date format is "YYYY/MM/DD" but this format is not supported in java.util.Date.So, we need to change String date1 to java.util.Date.

  1.  java.util.Date utilDate = dateFormat.parse(date1);


We cannot change java.util.Date to oracle.jbo.domain.Date.
So,we need to change java.util.Date to java.sql.Date and then java.sql.Date to oracle.jbo.domain.Date.


 
  1. java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
  2. jboDate = new oracle.jbo.domain.Date(sqlDate);

No comments:

Post a Comment