I am trying to store the value of date as 18/12/2016 into a date variable..
For example
Date date=new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date theDate = null;
try {
theDate = dateFormat.parse(date.toString());
System.out.println("Date parsed = " + dateFormat.format(theDate));
} catch (ParseException e) {
e.printStackTrace();
}
But the above code gives an error
java.text.ParseException: Unparseable date: "Mon Jun 18 00:00:00 IST 2012"
I have found examples where we can change the format and store it in the string datatype. But I need an example where we can store it in the date format itself.
Hope you guys understand my question.Please help..
Thanks.
EDIT-All the links given shows how to store the date into a string.I need to store the date in the format 18/12/2016 inside the date datatype itself.So it is not a duplicate Question.