简体   繁体   中英

how compare a date in string to system date

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","");

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

if( data.compareTo(currentDateandTime) == 0 )
    //The dates are equal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM