-1

I am working on android application in which i want to parse my date according to my format. But i am getting Unparseable date exception on it. My code is given below, please help me out to parse my date according to my format.

        SimpleDateFormat stestRequest = new SimpleDateFormat("EEE, MMM dd, yyyy hh:mm aa");
         try { 
            month = month +1;
Date  dateRequestSelected      = stestRequest.parse(day+", "+month+" "+day+", "+year+" "+hour+":"+minutes+ state); // 20, 1 20, 2016 10:28 am
    // I need a format like Monday, January 20, 2016 10:28 am
            } catch (ParseException e) {
                e.printStackTrace();
            }catch (Exception e) {
                e.printStackTrace();
            }

Please help me out here.

  • you don't have comma b/w 1 and 20 – Vivek Mishra Jan 18 '16 at 11:40
  • If you already *have* the values separately, why are you converting them into text and parsing them at all? Just set the relevant parts in a `Calendar`, e.g. with [`Calendar.set`](http://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#set-int-int-int-int-int-int-) – Jon Skeet Jan 18 '16 at 11:45

1 Answers1

2

EEE stays for day in the week (TEXT), but you have the day of the month (number). You have to use d instead of EEE. The same applies to MMM which should be M.

SimpleDateFormat stestRequest = new SimpleDateFormat("d, M dd, yyyy hh:mm aa");

You can read more about it here here

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • thanks for your answer here. It is still not displaying in date format which i want. It is displaying it like Wed Jan 20 12:14:00 GMT+04:00 2016. I need to display it like Wednesday January 20 12:40:00 am 2016 – Android_Zapier Jan 18 '16 at 13:15