Java Date Create ToDate(Object o)

Here you can find the source of ToDate(Object o)

Description

To Date

License

Apache License

Declaration

public static final Date ToDate(Object o) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static final Date ToDate(Object o) {
        return ToDate(ToString(o));
    }//ww  w  .j  ava  2  s .c om

    public static final Date ToDate(String s) {

        if (s.isEmpty())
            return null;

        Date dt;
        try {
            final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            dt = dateFormat.parse(s);
        } catch (Exception e) {
            dt = null;
        }

        return dt;
    }

    public static final String ToString(Object o) {
        return o != null ? o.toString() : "";
    }

    public static final String ToString(String s) {
        return s != null ? s : "";
    }
}

Related

  1. toDate(int flag, Date... date)
  2. toDate(long lastModified)
  3. toDate(long segundos)
  4. toDate(long time)
  5. toDate(long time)
  6. toDate(Object o)
  7. toDate(Object object)
  8. toDate(Object value)
  9. toDateFormat(Date date)