/** * Expects a <code>java.sql.Date</code>, <code>java.sql.Timestamp</code>, <code>java.sql.Time</code>, <code>java.util.Date</code>, * <code>Long</code> or string with format "yyyy-MM-dd". This method will truncate hours, minutes, seconds and * milliseconds to zeros, to conform with JDBC spec: * <a href="http://download.oracle.com/javase/6/docs/api/java/sql/Date.html">http://download.oracle.com/javase/6/docs/api/java/sql/Date.html</a>. * * <p>This method is tread-safe. * * @param value argument that is possible to convert to <code>java.sql.Date</code>: <code>java.sql.Date</code>, * <code>java.sql.Timestamp</code>, <code>java.sql.Time</code>, <code>java.util.Date</code>, <code>Long</code> or any object with toString() == <code>yyyy-mm-dd</code>. * @return <code>java.sql.Date</code> instance representing input value. */ public static java.sql.Date truncateToSqlDate(Object value){ if (value == null) { return null; } else if (value instanceof java.sql.Date) { return (java.sql.Date) value; } else if (value instanceof java.util.Date) { return truncateToSqlDate(((java.util.Date) value).getTime()); } else if (value instanceof Number) { return truncateToSqlDate(((Number) value).longValue()); } else { try { return java.sql.Date.valueOf(value.toString().trim()); } catch (IllegalArgumentException e) { throw new ConversionException("failed to convert: '" + value + "' to java.sql.Date", e); } } }
/** * Expects a <code>java.sql.Date</code>, <code>java.sql.Timestamp</code>, <code>java.sql.Time</code>, <code>java.util.Date</code>, * <code>Long</code> or string with format "yyyy-MM-dd". This method will truncate hours, minutes, seconds and * milliseconds to zeros, to conform with JDBC spec: * <a href="http://download.oracle.com/javase/6/docs/api/java/sql/Date.html">http://download.oracle.com/javase/6/docs/api/java/sql/Date.html</a>. * * <p>This method is tread-safe. * * @param value argument that is possible to convert to <code>java.sql.Date</code>: <code>java.sql.Date</code>, * <code>java.sql.Timestamp</code>, <code>java.sql.Time</code>, <code>java.util.Date</code>, <code>Long</code> or any object with toString() == <code>yyyy-mm-dd</code>. * @return <code>java.sql.Date</code> instance representing input value. */ public static java.sql.Date truncateToSqlDate(Object value){ if (value == null) { return null; } else if (value instanceof java.sql.Date) { return (java.sql.Date) value; } else if (value instanceof java.util.Date) { return truncateToSqlDate(((java.util.Date) value).getTime()); } else if (value instanceof Number) { return truncateToSqlDate(((Number) value).longValue()); } else { try { return java.sql.Date.valueOf(value.toString()); } catch (IllegalArgumentException e) { throw new ConversionException("failed to convert: '" + value + "' to java.sql.Date", e); } } }
/** * Expects a <code>java.sql.Date</code>, <code>java.sql.Timestamp</code>, <code>java.sql.Time</code>, <code>java.util.Date</code>, * <code>Long</code> or string with format "yyyy-MM-dd". This method will truncate hours, minutes, seconds and * milliseconds to zeros, to conform with JDBC spec: * <a href="http://download.oracle.com/javase/6/docs/api/java/sql/Date.html">http://download.oracle.com/javase/6/docs/api/java/sql/Date.html</a>. * * <p>This method is tread-safe. * * @param value argument that is possible to convert to <code>java.sql.Date</code>: <code>java.sql.Date</code>, * <code>java.sql.Timestamp</code>, <code>java.sql.Time</code>, <code>java.util.Date</code>, <code>Long</code> or any object with toString() == <code>yyyy-mm-dd</code>. * @return <code>java.sql.Date</code> instance representing input value. */ public static java.sql.Date truncateToSqlDate(Object value){ if (value == null) { return null; } else if (value instanceof java.sql.Date) { return (java.sql.Date) value; } else if (value instanceof java.util.Date) { return truncateToSqlDate(((java.util.Date) value).getTime()); } else if (value instanceof Number) { return truncateToSqlDate(((Number) value).longValue()); } else { try { return java.sql.Date.valueOf(value.toString().trim()); } catch (IllegalArgumentException e) { throw new ConversionException("failed to convert: '" + value + "' to java.sql.Date", e); } } }