1

I am trying to compare a date that is saved in a string to the system date... can anyone help me? here is the code...

            String currentDateandTime = new SimpleDateFormat("d-M-yyyy").format(new Date());

            data=preferences.getString("tgpref_data",""); 
            Log.e("dia atual",currentDateandTime);
            if(data.equals(""))
            {

            }
            else
            {

                if(data.equals(currentDateandTime))
                {
                    Log.e("do something the day have arrived","");

                }

                    Log.e("dont do nothing","");

            }
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • i have the preferences date like this : 14-9-2015 and the date in currentDateandTime like 14-9-2015 .... the dates are the same but somehow i cant enter in the if (do something the day have arrived) – Rafael Vieira Sep 14 '15 at 14:19
  • Trt this link ... http://stackoverflow.com/questions/8135689/how-to-compare-system-date-with-mydate-in-android-2-1?rq=1 – MPG Sep 14 '15 at 14:26

1 Answers1

2
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
Date date = format.parse(data);

if( data.compareTo(currentDateandTime) == 0 )
    //The dates are equal
Bruno Caceiro
  • 7,035
  • 1
  • 26
  • 45