I need to convert String (in date format) to TimeStamp.
IN first I did like this.
private Timestamp dateConverter(String date) {
Timestamp timestamp = null;
SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm");
Date parsedDate = null;
try {
parsedDate = dateFormat.parse(date);
timestamp = new java.sql.Timestamp(parsedDate.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
return timestamp;
}
Result was: ParseException: Unparseable date: "16 Jan 2020 11:02"
I tried by another way :
private Timestamp dateConverter(String date) {
DateTimeFormatter f = DateTimeFormatter.ofPattern("dd MMM yyyy HH:mm");
LocalDateTime ldt = LocalDateTime.parse(date , f);
return Timestamp.valueOf(ldt);
}
At this time I have Internal Server Error with DateTimeParseException: Text '16 Jan 2020 11:02' could not be parsed at index 3