Java Parse Date parseDate(Object val)

Here you can find the source of parseDate(Object val)

Description

parse to date

License

Apache License

Parameter

Parameter Description
val a parameter

Declaration

public static Date parseDate(Object val) 

Method Source Code

//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;
        }
    }
}

Related

  1. parseDate(final String value)
  2. parseDate(Long date, String format)
  3. parseDate(Map obj, String field, String format)
  4. parseDate(Object o)
  5. parseDate(Object str)
  6. parseDate(SimpleDateFormat parser, String str, String[] parsePatterns)
  7. parseDate(String _dateString)
  8. parseDate(String actual, DateFormat format, Pattern pattern)
  9. parseDate(String applyDt)