I've got a method to parse a String (yyyy-MM-dd HH:mm:ss.SSS) to a Date object using SimpleDateFormat.
public static Timestamp convertToTimestamp(String stringToFormat) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
try {
Date date = dateFormat.parse(stringToFormat);
Timestamp tstamp = new Timestamp(date.getTime());
return tstamp;
}
catch (ParseException e) {
return null;
}
}
However, when the Milliseconds end in 0, eg "2013-07-07 19:15:00.000", when I do the following to assign it to a Timestamp object:
Timestamp tstamp = new Timestamp(date.getTime());
the output is the following 2013-07-07 19:15:00.0
Is there any way to keep my precision of three decimal places on the Milliseconds? I realise I could probably do some sort of length check and manually add on 0's, but a more efficient, standard way of keeping this precision would be preferred