public final static java.util.Date getTime(int hours, int min, int sec)
throws InvalidDateException {
try {
Calendar cal = Calendar.getInstance(); java.util.Date today =
cal.getTime();
int year = getYear(today); int month = getMonth(today) - 1;
int date = getDay(today); cal.clear();
cal.set(year, month, date, hours, min, sec);
return cal.getTime();
} catch (Exception e) {
if (e instanceof InvalidDateException)
throw (InvalidDateException) e;
else {
String input = "" + hours + ':' + min + ':'+ sec;
}
}
}
public final static java.util.Date getTime(int year,int month,int day,int
hours,int min,intsec)
throws InvalidDateException {
try {
Calendar cal = Calendar.getInstance(); cal.clear();
cal.set(year, month-1, day, hours, min, sec); return
cal.getTime();
} catch (Exception e) {
if (e instanceof InvalidDateException)
throw (InvalidDateException) e;
else {
String input = "" + hours + ':' + min + ':' + sec;
}
}
}
public static String getXML(Date date) throws InvalidDateException{
return getXML(date, "Year", "Month", "Day");
}
public static String getXML(Date date, String yearTag, String monthTag,
String dayTag) throws InvalidDateException{
try {
Calendar cal = Calendar.getInstance();cal.clear();
cal.setTime(date);StringBuffer buffer = new
StringBuffer(41);
buffer.append("<");
buffer.append(yearTag);buffer.append(">");
buffer.append(cal.get(cal.YEAR));buffer.append("</");buffer.append(yearTag);
buffer.append(">");buffer.append("<");buffer.append(monthTag);
buffer.append(">");buffer.append(cal.get(cal.MONTH) +
1);buffer.append("</");
buffer.append(monthTag);buffer.append(">");buffer.append("<");buffer.append(
dayTag);
buffer.append(">");buffer.append(cal.get(cal.DATE));buffer.append("</");
buffer.append(dayTag);buffer.append(">");return
buffer.toString();
} catch (Exception e) {}
}
public static int getYear(Date date) throws InvalidDateException{
try {
Calendar cal = Calendar.getInstance();cal.clear();
cal.setTime(date);int yy = cal.get(Calendar.YEAR);
if (yy < 100)
yy += 1900;
return yy;
} catch (Exception e) { }
}
public static boolean isSameDay(Date date1, Date date2) {
if ( date1 == null && date2 == null ){
return true;
}
if ( date1 == null || date2 == null ){
return false;
}
Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1);
Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2);
return (cal1.get(Calendar.DAY_OF_MONTH) ==
cal2.get(Calendar.DAY_OF_MONTH)
&& cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH)
&& cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR));
}
public static Date parse( String date, String simpleFormat ) throws
InvalidDateException
{
try
{
return new SimpleDateFormat(simpleFormat).parse(date);
}
catch ( Exception e )
{ }
}
public static Date toStandardDate(String date) throws InvalidDateException{
try{
return dateFormatter.parse(date);
} catch (Exception e){}
}
public static Date toStandardDateTime(String date) throws
InvalidDateException{
try{
return dateTimeFormatter.parse(date);
} catch (Exception e){ }
}
public static String toStandardString(Date date) throws
InvalidDateException{
try{
return dateFormatter.format(date);
} catch (Exception e){}
}
public static String toStandardTimeString(Date date) throws
InvalidDateException{
try{
return dateTimeFormatter.format(date);
} catch (Exception e){}
}
}
Regards
Ramesh Kesavanarayanan
[EMAIL PROTECTED]
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".