Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concat Two Strings then Convert to Date in Java

I need to concat two strings together in Java and then format the string and make it a Date object.

The two strings that I have at the moment are 31/01/2012 and 20:00 and I want to do something like:

try {
  DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm");
  Date result = new Date();
  String tempDate = date + " " + f;
  result = formatter.parse(tempDate);
} catch (ParseException e) {
  ...etc
}

Can someone help me figure how to add the two strings together. Any help would be appreciated!

like image 791
SNpn Avatar asked Jun 21 '26 08:06

SNpn


2 Answers

Your concatenation is fine. Yet it seems that your format is "dd/MM/yyyy HH:mm"

like image 129
Jean Logeart Avatar answered Jun 22 '26 20:06

Jean Logeart


The code looks good. Just correct the format it should be

"dd/MM/yyyy HH:mm"

like image 42
Mukul Goel Avatar answered Jun 22 '26 21:06

Mukul Goel