开发者

how to exclude a string date formattee from being tested against another string?

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{


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. 
     }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜