how to convert string date to java.util.date in java .
String date="12-12-2014 10:00:00"
Date d=2014-12-12 10:00:00;
Need this string date in date formate
how to convert string date to java.util.date in java .
String date="12-12-2014 10:00:00"
Date d=2014-12-12 10:00:00;
Need this string date in date formate
Try following code:
String test="12-12-2014 10:00:00";
Date date=new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").parse(test);
String OutputDate=new SimpleDateFormat("yyyy-dd-MM HH:mm:ss").format(date);
System.out.println(OutputDate);
Output :
2014-12-12 10:00:00
The dig over here is to parse a string with date attributes using SimpleDateFormat
into java.util.Date
.
For more on SimpleDateFormat
visit this link.
Try this:
String date = "12-12-2014 10:00:00";
DateFormat inputDateFormat = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
DateFormat outputDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(outputDateFormat.format(inputDateFormat.parse(date)));
Output:
2014-12-12 10:00:00
Basically you need to parse your date in the format provided and from one format (inputDateFormat) you need to convert it to the other format (done by outputDateFormat).