Here you can find the source of toString(Object date)
public static String toString(Object date)
//package com.java2s; import java.text.*; public class Main { public static DateFormat OUT_DATE_FORMAT = new SimpleDateFormat( "dd/MM/yyyy"); public static DateFormat OUT_TIME_FORMAT = new SimpleDateFormat( "H:mm:ss"); public static DateFormat OUT_DATETIME_FORMAT = new SimpleDateFormat( "d/M/yyyy H:mm:ss"); public static DateFormat OUT_TIMESTAMP_FORMAT = new SimpleDateFormat( "d/M/yy H:mm:ss.SSS"); /**/*from w w w.ja v a 2 s . c o m*/ * Convert an Object to a String using Dates */ public static String toString(Object date) { if (date == null) { return null; } if (java.sql.Timestamp.class.isAssignableFrom(date.getClass())) { return OUT_TIMESTAMP_FORMAT.format(date); } if (java.sql.Time.class.isAssignableFrom(date.getClass())) { return OUT_TIME_FORMAT.format(date); } if (java.sql.Date.class.isAssignableFrom(date.getClass())) { return OUT_DATE_FORMAT.format(date); } if (java.util.Date.class.isAssignableFrom(date.getClass())) { return OUT_DATETIME_FORMAT.format(date); } throw new IllegalArgumentException("Unsupported type " + date.getClass()); } }