Convert string to Date and compair it to Current date : <p>Hello Guys This problem is driving me crazy right now. I have a string in my database called <code>dueDate</code> with value <code>Jan 18, 2018</code>. I retrieved it and save it in a string in my recyclerAdapter with <code>String dueDate = transactionTasks.get(position).get_transactiontaskpaydet().toString();</code></p>

<p>Now i wanna compare it with the current date and if the due date is after my current date it should display the dueDate with red color.</p>

<p>bellow are my coded.</p>

<pre><code>String dueDate = transactionTasks.get(position).get_transactiontaskpaydet().toString();
    Date cdate = new Date();
    Date ddate = new Date(dueDate);

    if(cdate.after(ddate)){
        holder.date.setTextColor(Color.RED);
    }
</code></pre>

<p>This codes work perfectly but the problem is <code>Date(dueDate);</code> is deprecated. And when i use another method that uses a <code>try</code> and <code>catch</code>, i don't get any result. </p>

<p>Below are the codes </p>

<pre><code>SimpleDateFormat format = new SimpleDateFormat("E, MMM dd yyyy");
    Date curDate = new Date();
        try {
            Date datedue = format.parse(dueDate);
            if(curDate.after(datedue)) {
                holder.date.setTextColor(Color.RED);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
</code></pre>

<p>And if I try creating the <code>Date</code> outside the <code>try</code> block by using <code>Date duedate = null;</code> I get an error because its not getting the values inside the <code>try</code> block. this is driving me crazy because I shouldn't use deprecated code even if it works perfectly. </p>

<p>All the answers I found didn't work for me. I just need to be able to convert a string to a date so I can compare it with the current date. Thanks Guys</p>
