Various Date Converter, Formatter and Validations Reusable Methods in OAF

/**===============================================
* Methods related to Date Operation Starts Here *
=================================================*/

/**
* Method that returns the current system date.
* @return returns date of type oracle.jbo.domain.Date
*/
public static oracle.jbo.domain.Date getCurrentDate()
{
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
// System.out.println(“The current time is “+cal.getTime());
return new oracle.jbo.domain.Date(new java.sql.Date(cal.getTime().getTime()));
}

public static oracle.jbo.domain.Date getCurrentDateTime()
{
return new oracle.jbo.domain.Date(new Timestamp((new Date()).getTime()));
}

public static String dateToString(Date date)
{
SimpleDateFormat dateDisplayFormat = new SimpleDateFormat(“dd-MMM-yyyy”);
return dateDisplayFormat.format(date);
}

public static String getCurrentYear(Date date)
{
SimpleDateFormat dateDisplayFormat = new SimpleDateFormat(“yyyy”);
return dateDisplayFormat.format(date);
}

public static String jboDateToString(oracle.jbo.domain.Date date)
{
return dateToString(date.getValue());
}

public static Date stringToDate(String date)
{
SimpleDateFormat dateDisplayFormat = new SimpleDateFormat(“dd-MMM-yyyy”);
try
{
return dateDisplayFormat.parse(date);
}
catch(ParseException e)
{
e.printStackTrace();
}
return null;
}

public static oracle.jbo.domain.Date stringToJboDate(String date)
{
if(stringToDate(date)!=null)
return new oracle.jbo.domain.Date(new java.sql.Date(stringToDate(date).getTime()));
else
return null;
}

public static boolean isBetween(oracle.jbo.domain.Date date,oracle.jbo.domain.Date compareDate1,oracle.jbo.domain.Date compareDate2)
{
return (date.compareTo(compareDate1)!=-1 && date.compareTo(compareDate2)!=1)?true:false;
}

/*==================================================================*/

 

 

 

Recent Posts

Start typing and press Enter to search