I want to parse the date into a desired format but i am receiving an exception every time. i know it is easy to implement but i am facing some problem don\'t know where exac
Maybe you need to tackle different input formats Then catch the currently unmanaged format exception (just a sample):
private String getconvertdate(String date) {
System.out.println(date.length());
DateFormat inputFormat = null;
if(date.length() == 20)
inputFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss",Locale.ENGLISH);
if(date.length() == 10)
inputFormat = new SimpleDateFormat("yyyy-MM-dd",Locale.ENGLISH) ;
if(null == inputFormat)
return "Format invalid";
inputFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
DateFormat outputFormat = new SimpleDateFormat("dd-MMM-yyyy",Locale.ENGLISH);
Date parsed = null;
try {
parsed = inputFormat.parse(date);
} catch (ParseException e) {
return "Input Date invalid";
}
String outputText = outputFormat.format(parsed);
return outputText;
}