I have this problem converting java.sql.Timestamp.toString back to java.sql.Timestamp. Given element = "2012-08-01 00:00:00.0" and using the code below would return a ParseException telling that element is an Unparseable date.
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())
}
Is there a way to convert java.sql.Timestamp.toString() back to java.sql.Timestamp?
Using Date is a bad idea. Date does not handle TimeZone format etc well. See if you can use Calendar Object. Also note that something like date.getYear() will give you 2012-1900 and not the year as you expect. I gave you an example using Date below :a