0

I have a string with date in it. I want to convert it into date. For example

    String str = "Fri Oct 23 00:00:00 PKT 2015";

How to convert it into java date.

Arsaceus
  • 293
  • 2
  • 19
Atif Shahzad
  • 153
  • 2
  • 7

1 Answers1

0

Use the SimpleDateFormat class :

SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");

String dateInString = "7-Jun-2013";

try {

    Date date = formatter.parse(dateInString);
    System.out.println(date);
    System.out.println(formatter.format(date));

} catch (ParseException e) {
        e.printStackTrace();
}

Output :

Fri Jun 07 00:00:00 MYT 2013
07-Jun-2013
Wael Sakhri
  • 397
  • 1
  • 8
  • The problem is i have String with "Fri Oct 23 00:00:00 PKT 2015" and i want to convert this string into data. What should be date format for this string. – Atif Shahzad Feb 03 '16 at 14:31
  • 1
    I solve it SimpleDateFormat formatter = new SimpleDateFormat("EE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH); formatter.parse("Fri Oct 23 00:00:00 PKT 2015"); – Atif Shahzad Feb 03 '16 at 14:50