I need date format in dd-mm-yyyy
format in jsp.My database
(dd/mm/yyyy-having date datatype in db) is read to jsp(using form bean, CmFrm.getExpireDate() - having datatype as string).
It is now read as yyyy-mm-dd hh:mm:ss.a
in jsp i want it to read in dd-mm-yyyy
format.
I have tried using --
String txtdate =CmFrm.getExpireDate();
SimpleDateFormat pd = new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date date = (Date) pd.parse(txtdate);
String DisplayDate= df.format(date);
System.out.println("MyExpireDate.."+DisplayDate);
I get unparsable
error.
I have applied format function alone as -
String txtdate =CmFrm.getExpireDate();
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
System.out.println("Date.."+df.format(txtdate));
here jsp goes blank
.
please help as how to display date on jsp in dd-mm-yyyy
.
Should do you good...
String MyDate = CmFrm.getExpireDate();
SimpleDateFormat parseDate = new java.text.SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat formatDdate = new java.text.SimpleDateFormat("yyyy-MM-dd");
Date date = (Date) parseDate.parse(MyDate);
String DisplayDate= formatDate.format(date);
Output example: 2016-11-19
I tried your first code and I don't get any exceptions:
String txtdate = "06/06/2012";
SimpleDateFormat pd = new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
date = (Date) pd.parse(txtdate);
} catch (ParseException e) {
e.printStackTrace();
}
String DisplayDate= df.format(date);
System.out.println("MyExpireDate.."+DisplayDate);
When I execute the following, I get:
MyExpireDate..2012-06-06
Maybe you've imported the wrong date libraries? I imported these:
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;