-4

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.

VH-NZZ
  • 5,248
  • 4
  • 31
  • 47
  • 2
    Read `SimpleDateFormat` – Subhrajyoti Majumder May 05 '14 at 07:23
  • You can use `SimpleDateFormat` to format the date. – Subir Kumar Sao May 05 '14 at 07:23
  • 2
    possible duplicate of [How to parse a date?](http://stackoverflow.com/questions/999172/how-to-parse-a-date) – Basil Bourque May 05 '14 at 07:27
  • 1
    I downvoted this question because date formatting and conversion is _extensively_ documented on the open web and just any elementary search with reasonable keywords on any search engine will return code samples. Many hits will also link back to SO. Also this is the kind of questions that just clutter SO and esp. the `Java` tag and show little if no effort on OP's part to do basic research. This question should be closed. – VH-NZZ May 05 '14 at 07:52
  • @BalusC I suppose one kind feeds the other. Poor Monday so far. – VH-NZZ May 05 '14 at 08:00

2 Answers2

1

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
Braj
  • 46,415
  • 5
  • 60
  • 76
0

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);
    }
subodh
  • 6,136
  • 12
  • 51
  • 73