如何将String类型转化为Timestamp类型,急.

解决方案 »

  1.   

    Timestamp tt=Timestamp.valueOf(ttString)
      

  2.   

    如果这个String的格式符合Timestamp.valueOf()的要求,就调用这个方法;
    如果不符合,就自己把string里头的每个单元解析出来,再new一个Timestamp
      

  3.   

    public static java.sql.Timestamp string2SqlTimestamp(String sDateTimeValue)
        {
            java.sql.Timestamp timestamp = null;
            if (sDateTimeValue == null)
            {
                timestamp = null;
            }
            else
            {
                try
                {
                    timestamp = java.sql.Timestamp.valueOf(sDateTimeValue);
                }
                catch(Exception e)
                {
                    timestamp = null;
                }
            }
            return timestamp;
        }
    试试吧
      

  4.   

    ............................
    shit,还以为是沙发呢
      

  5.   

     public static Timestamp stringToTimestamp(String timestampStr, String format) {
    if ( timestampStr == null || timestampStr.trim ( ).equals ( "" ) ) {
    return null;
    }
    SimpleDateFormat dateFormat = new SimpleDateFormat ( format );
    try {
    Date date = dateFormat.parse ( timestampStr );
    return new Timestamp ( date.getTime ( ) );
    } catch ( Exception e ) {
    System.out.println ( e.getMessage ( ) );
    }
    return null;
    }
    ---------------------------------------
    format   可以为   
      yyyy-MM-dd   HH:mm:ss
      

  6.   

    谢谢freebird_PS和lxq_del,但不能使用valueof,因为valueof对格式的要求太高了.