我有這個問題轉換java.sql.Timestamp.toString
回到java.sql.Timestamp
。鑑於element = "2012-08-01 00:00:00.0"
和使用下面的代碼將返回ParseException
告訴element
是Unparseable date
。Groovy java.sql.Timestamp.toString()到java.sql.Timestamp
import java.sql.Timestamp
import java.text.SimpleDateFormat
Timestamp string_timestamp(String element) {
if(!date)
return null
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy")
// error lies here! //
Date parsedDate = dateFormat.parse(date)
return new Timestamp(parsedDate.getTime())
}
有沒有辦法來java.sql.Timestamp.toString()
轉換回java.sql.Timestamp
?
你可以提供一個代碼片段來關注。謝謝。 –
您的輸入是「2012-08-01 00:00:00.0」正確嗎?您的SimpleDateFormatter與您正在使用的不同。我會在幾分鐘後發佈代碼。 –
@DrJava添加了代碼..還添加了try catch來正確地捕獲異常以及null檢查。謝謝。 –