Here you can find the source of toDate(Object obj)
public static Date toDate(Object obj)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static Date toDate(Object obj) { if (obj instanceof java.util.Date) { return (Date) obj; }//from w ww .j av a 2s . c o m if (obj instanceof java.sql.Date) { java.sql.Date sqlDate = (java.sql.Date) obj; return new Date(sqlDate.getTime()); } if (obj instanceof Calendar) { Calendar cal = (Calendar) obj; return new Date(cal.getTimeInMillis()); } if (obj instanceof java.sql.Time) { java.sql.Time sqlTime = (java.sql.Time) obj; return new Date(sqlTime.getTime()); } if (obj instanceof java.sql.Timestamp) { java.sql.Timestamp sqlTimestamp = (java.sql.Timestamp) obj; return new Date(sqlTimestamp.getTime()); } throw new IllegalArgumentException("Unable to convert object of type '" + obj.getClass() + "' to Date."); } }