title: How to compare if the new date is after the old date in android
body: <p>I'm trying to see how I can compare if the new date is after the old date if so no data will be shown from the firebase database. I am having trouble with this because my app crashes when I test it I believe I'm doing something wrong. Can someone help me with this issues? Below is my code. Thanks in advance</p>
  <pre><code> //Code
      
      if(dataSnapshot.exists()){
                          //progressBar.setVisibility(View.GONE);
  
  
  
                          for (DataSnapshot postsnapshot : dataSnapshot.getChildren()) {
  
  
                              UserInformation2 upload=postsnapshot.getValue(UserInformation2.class);
  
  
                              SimpleDateFormat simpleDateFormat = new SimpleDateFormat(&quot;M-dd-yyyy&quot;);
                              //String now = simpleDateFormat.format(new Date());
  
                             Date d=new Date();
                              String AdCreationDate = postsnapshot.child(&quot;created&quot;).getValue(String.class);
                              //SimpleDateFormat df = new SimpleDateFormat(&quot;yyyy/MM/dd&quot;)
  
                              try {
  
                                  Date new_date = simpleDateFormat.parse(String.valueOf(d));
                                  Date old_date = simpleDateFormat.parse(AdCreationDate);
  
  
                                  if(new_date.after(old_date)){
                                      // Your time expired do your logic here.
                                      Toast.makeText(getContext(), &quot;Your data expired&quot;, Toast.LENGTH_SHORT).show();
                                  }else{
                                      myUploads.add(upload);
  
                                      recyclerView.invalidate();
                                  }
  
                              } catch (ParseException e) {
                                  e.printStackTrace();
                              }
  
                              //simpleDateFormat.format(d);
                             //Date e=new Date(old);
  
  
  
  
  
  
  
  
  
  
  
  
                          }
  
                          linearLayoutWithoutItems.setVisibility(View.GONE);
                          recyclerView.setVisibility(View.VISIBLE);
  </code></pre>
  <p>Stacktrace</p>
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.myapp.tout, PID: 22667
      java.lang.IllegalArgumentException
          at java.util.Date.parse(Date.java:638)
  </code></pre>