¿Cómo excluir un formato de fecha de cadena de ser probado contra otra cadena?

I am retrieving a list of dates. One by one and testing them against another date for mated August 27,2011 I have dates for mated in two ways.

August 27,2011
August 2011.

How could I exclude testing the date formatted August 2011? When I try to parse it it will give me a paserexception. So how could I exclude these dates formatted that way?

EDIT:

 date = postIt.next().text();
                     Log.v("Dates", date);

                     try {
                        Date itemDate = sdf.parse(date);
                    } catch (ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }


 if(itemDate.equals(isToday)){
                             nm = (NotificationManager) this
                                        .getSystemService(Context.NOTIFICATION_SERVICE);
                                      CharSequence from = "app";
                                      CharSequence message = message";
                                      PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Example.class), 0);
                                      Notification notif = new Notification(R.drawable.icon,
                                               message , System.currentTimeMillis());
                                              notif.setLatestEventInfo(this, from, message, contentIntent);
                                              nm.notify(1, notif);


                         }

                         else{

preguntado el 27 de agosto de 11 a las 21:08

how about using a regex? -

could you give a little more details -

what do you mean "testing them against another date" ? -

no usar toString() for that. Can you show your code? -

Definir Date itemDate = null outside the try/catch. Otherwise it's not visible below -

1 Respuestas

Catch the parse exception - this will indicated incorrectly formatted date according to your expectations. For example:

for (String dateString : dateStrings) {
     try {
          Date date = dateFormat.parse(dateString);
     } catch (ParseException ex) {
         // date can't be parsed, ignore & continue. 
     }
}

Respondido 28 ago 11, 01:08

ive tried that but it doesn't continue if the date isnr fornstted correctly - yoshi24

if the date is formatted correctly how will it continue comparing it? Could you show an example in code if you have - yoshi24

So is that for() comparing the Date to the dateStrings? - yoshi24

that's a loop I assume you have, because you haven't shown anything of your code - Bozho

I was using if() statements. It would probably work better to us for, what do you think? - yoshi24

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.