Here you can find the source of parseDate(Object val)
Parameter | Description |
---|---|
val | a parameter |
public static Date parseDate(Object val)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { /**/* www .j a v a 2 s . c om*/ * parse to date * @param val * @return */ public static Date parseDate(Object val) { if (val == null) return null; if (val instanceof Date) { return (Date) val; } else if (val instanceof Calendar) { return ((Calendar) val).getTime(); } else if (val instanceof Long) { return new Date(((Long) val).longValue()); } return null; } /** * parse to date * @param val * @return */ public static Date parseDate(String val, String format) { DateFormat df = new SimpleDateFormat(format); try { return df.parse(val); } catch (ParseException e) { return null; } } }