Android: Comparing getDat() with current Date

I have this CalendarView below

enter image description here

and if i click that day which is the Date today it will popup a dialog.. but this Calendar wont popup if u clicked a date before the CurrentDate it will just say u can't add event before the current day/time.. and is running well if i click any day after the date today, but when i click the date today i will say a message just like when i click the date before it...

Here is my Code for comparing dates

long currentTime;
Date curr = new Date();
currentTime = curr.getTime();
if(cw.getDate() >= currentTime || formatDate(cw.getDate()) == formatDate(currentTime))
{
            Dialog d = new Dialog(ScheduleActivity.this);
            //some code for setting up the dialog
            d.show();

}
else
{
        Toast toast = Toast.makeText(ScheduleActivity.this, Long.toString(cw.getDate())+" || "+Long.toString(currentTime),10000);
        toast.show();

        Log.d("timecheck", formatDate(cw.getDate())+" || "+ formatDate(currentTime));
}

I just used that formatDate with a Format of MM/dd/yyyy just to compare the two dates cuz comparing the time stamp alone still does not work (using ">=" )

Btw the toast are changed so i can see what values are being compared... in Milliseconds they are defferent really but when i format it to MM/dd/yy supposed to be it will see it as the same... but it wont go through the if part it'll go to the else part.. i Logged the formattedDate in the logcat, logcat below..

Logcat Logs enter image description here

preguntado el 31 de julio de 12 a las 14:07

2 Respuestas

Necesitarás usar equals en lugar de == to compare the strings returned from formatDate:

if(cw.getDate() >= currentTime || formatDate(cw.getDate()).equals(formatDate(currentTime)))

Respondido 31 Jul 12, 14:07

ohh yeah i forgot String is an Object too.. thanks man! appreciated it.. it works just fine! - códigos de limón

Your pop up is not appearing as you are comparing all the inputs with the current date try with entering other values for comparision by adding previous dates and try it out again it will work:)

Respondido 31 Jul 12, 14:07

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