将时间转换为时间戳,java.sql.Timestamp

/* 
     * 将时间转换为时间戳
     * java.sql.Timestamp <<-- String
     */    
    public static Timestamp dateToStamp(String timeString)throws ParseException{
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        java.util.Date date = simpleDateFormat.parse(timeString);
        long ts = date.getTime();
        java.sql.Timestamp resTimestamp = new Timestamp(ts);
        return resTimestamp;
    }

你可能感兴趣的:(java基础)