Here you can find the source of toDate(Object o)
public static Object toDate(Object o)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public final static String d_cst_fmt = "EEE MMM dd HH:mm:ss zzz yyyy"; public final static String d_long_fmt = "yyyyMMddHHmmss"; public final static String d_short_fmt = "yyyyMMdd"; public static Object toDate(Object o) { SimpleDateFormat sdf = null; try {//from w ww.j av a 2 s . co m if (o instanceof Date) { return o; } else if (o instanceof String) { String text = ((String) o).trim(); int len = text.length(); if (len == d_cst_fmt.length()) { return new SimpleDateFormat(d_cst_fmt, Locale.US).parse(text); } else if (len == d_long_fmt.length()) { return new SimpleDateFormat(d_long_fmt).parse(text); } else if (len == d_short_fmt.length()) { return new SimpleDateFormat(d_short_fmt).parse(text); } } return null; } catch (Exception e) { System.err.println("Can't convert date : " + o); return null; } } public static int length(Object fv) { return (fv != null) ? fv.toString().trim().length() : 0; } }