Java SQL Date From toDate(Object obj)

Here you can find the source of toDate(Object obj)

Description

to Date

License

Apache License

Declaration

public static Date toDate(Object obj) 

Method Source Code

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

import java.util.Calendar;

import java.util.Date;

public class Main {
    public static Date toDate(Object obj) {
        if (obj instanceof java.util.Date) {
            return (Date) obj;
        }//from  w ww .j  av  a  2s  .  c o m

        if (obj instanceof java.sql.Date) {
            java.sql.Date sqlDate = (java.sql.Date) obj;
            return new Date(sqlDate.getTime());
        }

        if (obj instanceof Calendar) {
            Calendar cal = (Calendar) obj;
            return new Date(cal.getTimeInMillis());
        }

        if (obj instanceof java.sql.Time) {
            java.sql.Time sqlTime = (java.sql.Time) obj;
            return new Date(sqlTime.getTime());
        }

        if (obj instanceof java.sql.Timestamp) {
            java.sql.Timestamp sqlTimestamp = (java.sql.Timestamp) obj;
            return new Date(sqlTimestamp.getTime());
        }

        throw new IllegalArgumentException("Unable to convert object of type '" + obj.getClass() + "' to Date.");
    }
}

Related

  1. toDate(int value)
  2. toDate(java.sql.Date sqlDate)
  3. toDate(java.util.Date date)
  4. toDate(Object date)
  5. toDate(Object o)
  6. toDate(Object value)
  7. toDate(String dateString)
  8. toDate(String s)
  9. toDateFromString(String str)