I want to convert Date format from 2017-02-08 00:00:00.0 to dd/MM/yyyy(08/02/2017). I tried with the following code.
String dateInString =bean.getDate();
Date date = null;
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
if (bean.getDate().matches("^[0-9]{2,4}(-[0-9]{1,2}){2}\\s[0-9]{1,2}(:[0-9]{1,2}){2}\\.[0-9]{1,}$")) {
try {
date = formatter.parse(dateInString);
} catch (ParseException e) {
e.printStackTrace();
}
}
But I am getting NullPointerException in date = formatter.parse(dateInString);
line.