I am trying to convert String to Timestamp to save in my postgresql database using Java Springboot. The problem I'm facing is a problem I read in many different topics here but it seems I might be missing something and I cannot see what exactly. My assumption is that something wrong is happening to SimpleDateFormat object and it's not formatting the date appropriately.
This is my function to convert from String to Timestamp. The string i pass here is taken from Android sending it with Volley requests.
private Timestamp convertDate(String date){
try {
System.out.println("Passed date to method: " + date);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd HH:mm");
Date parsedDate = simpleDateFormat.parse(date);
System.out.println("Pre returned date: " + parsedDate);
Timestamp timestamp = new Timestamp(parsedDate.getTime());
System.out.println("Pre returned timestamp: " + timestamp);
return timestamp;
}catch (ParseException e){
return null;
}
}
And this is what is in my logs.
Passed date to method: 11/06 12:47
Pre returned date: Fri Nov 06 12:47:00 UTC 1970
Pre returned timestamp: 1970-11-06 12:47:00.0
Any help would be greatly appreciated.