Conversion.java 984 Bytes
package com.huaheng.api.SSP;


import java.sql.Date;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class Conversion {

    /**
     * String转timestamp
     * @param str
     * @return
     */
    public Timestamp strToDateLong(String str) {
        Timestamp ts = new Timestamp(System.currentTimeMillis());
        String tsStr = str;
        try {
            ts = Timestamp.valueOf(tsStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ts;
    }

    /**
     * Date转String
     * @param tsp
     * @return
     */
    public String dateLongToStr(Date tsp){
        String dateStr = "";
        Date date = tsp;
        //format的格式可以任意
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            dateStr = sdf.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dateStr;
    }
}