Search code examples
datesimpledateformatdate-conversion

String to date conversion in Java exception


I know my question is deprecated but i can't really solve my problem.

Well i'm trying to convert a String to Date, but i'm getting unappeasable date exception. Here is my code:

String issued = "Thu, 31 Mar 2015 08:21:47 GMT";
SimpleDateFormat formatter2 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");

            try {

                Date date = formatter2.parse(issued);

                Log.d("issued date", ""+date);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

Can any body tell me what is my problem !!

Thank you.


Solution

  • I've solved the problem, well t's a partial solution!.

    String issued = "Thu, 02 Apr 2015 12:10:02";
    SimpleDateFormat formatter2 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss", Locale.US);
    
                try {
    
                    Date date = formatter2.parse(issued);
    
                    Log.d("issued date", ""+date);
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
    

    1) I added , Locale.US 2) I removed time zone (GMT)

    Good luck.