如何比较字符串中的日期与系统日期

时间:2015-09-14 14:17:00

标签: java android

我正在尝试将字符串中保存的日期与系统日期进行比较......任何人都可以帮助我吗?这是代码......

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

            }

1 个答案:

答案 0 :(得分:2)

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

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