Java Timestamp Create toTimestamp(Object objInParam)

Here you can find the source of toTimestamp(Object objInParam)

Description

to Timestamp

License

GNU General Public License

Declaration

public static Timestamp toTimestamp(Object objInParam) 

Method Source Code

//package com.java2s;
/*//  w  w  w  . ja  v a  2  s .c  om
 Pulsar
 Copyright (C) 2013-2015 eBay Software Foundation
 Licensed under the GPL v2 license.  See LICENSE for full terms.
 */

import java.sql.Timestamp;
import java.util.Date;

public class Main {
    public static Timestamp toTimestamp(Object objInParam) {
        Timestamp ts = null;
        if (objInParam instanceof Timestamp)
            ts = (Timestamp) objInParam;
        else if (objInParam instanceof Number)
            ts = new Timestamp(((Number) objInParam).longValue());
        else if (objInParam instanceof Date)
            ts = new Timestamp(((Date) objInParam).getTime());
        else if (objInParam instanceof String) {
            if ("now".equalsIgnoreCase((String) objInParam))
                ts = new Timestamp(System.currentTimeMillis());
            else
                ts = Timestamp.valueOf((String) objInParam);
        } else if (objInParam == null)
            ts = new Timestamp(System.currentTimeMillis());
        return ts;
    }
}

Related

  1. toTimestamp(final String pValue)
  2. toTimestamp(java.sql.Date date)
  3. toTimestamp(long ts)
  4. toTimestamp(long value)
  5. toTimestamp(Object dateobj)
  6. toTimestamp(String _sDate)
  7. toTimestamp(String dateTime)
  8. toTimestamp(String dateTime)
  9. toTimestamp(String dt)