Possible Duplicate:
String to Date in Different Format in Java
I want to convert String to Date in different Format.
String d = "07:33:01 PM 26/11/2011";
How can i covert it to 26/11-19h30
?
Possible Duplicate:
String to Date in Different Format in Java
I want to convert String to Date in different Format.
String d = "07:33:01 PM 26/11/2011";
How can i covert it to 26/11-19h30
?
DateFormat formatter = new SimpleDateFormat("MM/dd-H\hm");
date = (Date)formatter.parse(d);
You will need to import java.util.* and import java.text.*
String d = "07:33:01 PM 26/11/2011";
Date date = new SimpleDateFormat("d/MM-HH\hmm", Locale.ENGLISH).parse(d);
Have a look at SimpleDateFormat. You can parse to custom date formats using this class.
String d = "07:33:01 PM 26/11/2011";
SimpleDateFormat formatterIn = new SimpleDateFormat("hh:mm:ss a dd/MM/yyyy");
SimpleDateFormat formatterOut = new SimpleDateFormat("dd/MM-HH'h'mm");
Date date = formatterIn.parse(d);
System.out.println(formatterOut.format(date));
It converts to 26/11-19h33, do you want to round to 26/11-19h30?