怎么将String类型转化为Timestamp类型

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

------解决方案--------------------
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;
}


试试吧
------解决方案--------------------
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
阅读
上一篇:关于多态的有关问题 下一篇:返回列表