import java.sql.Date;
class sqlDate
{
//Method to convert java.util.Date to java.sql.Date
public static Date UtilDateToSqlDate(java.util.Date utilDate) {
Date sqlDate = null;
if (utilDate != null) sqlDate = new Date(utilDate.getTime());
return sqlDate;
}
// Method to convert java.sql.Date to java.util.Date
public static java.util.Date SqlDateToUtilDate(Date sqlDate) {
java.util.Date utilDate = null;
if (sqlDate != null) utilDate = new java.util.Date(sqlDate.getTime());
return utilDate;
}
public static void main(String args[])
{
java.util.Date d1 = new java.util.Date();
System.out.println("Util Date : "+ d1);
java.sql.Date d2 =UtilDateToSqlDate(d1);
System.out.println("Sql Date : " + d2);
java.util.Date d3= SqlDateToUtilDate(d2);
System.out.println("Back to Util Date : "+ d3);
}
}
Nice tutorial...keep it UP
ReplyDelete