I have date in this format Tue May 20 00:00:00 PKT 2014
which I want to convert to 20-05-2014
.
I take this value from an ADF inputDate component. Please help.
I have date in this format Tue May 20 00:00:00 PKT 2014
which I want to convert to 20-05-2014
.
I take this value from an ADF inputDate component. Please help.
Try this one along with your locale using SimpleDateFormat
// Locale for Pakistan region
Locale aLocale = new Locale.Builder().setRegion("PK").build();
// Tue May 20 00:00:00 PKT 2014
SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd kk:mm:ss z yyyy", aLocale);
Date date = format.parse("Tue May 20 00:00:00 PKT 2014");
// 20-05-2014
SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy", aLocale);
System.out.println(format1.format(date));
output:
20-05-2014
Try this util method,
static public String getDateInDDMMYY(Date date) throws ParseException{
Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String _24HoursFTimeToConvert = formatter.format(date);
SimpleDateFormat _24HourSDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat _12HourSDF = new SimpleDateFormat("dd-MM-yyyy");
Date _24HourDt = _24HourSDF.parse(_24HoursFTimeToConvert);
return _12HourSDF.format(_24HourDt);
}