Calculating date intervals between two dates as i have the date in string. How could i do this..?
<p>Friends, </p>

<p>I was intended to know how to implement the date and time functions for android and java.</p>

<p>I'm developing an application which shows the posted date of images. I'm showing that date in a list view. For example. I'm showing something like // posted on : 20/3/2012. Instead of it, i want to calculate the time interval betweeen two date and the date i have in type string. Besides, i want to calculate seconds, minutes, hours too. How can i do this..?</p>

<p>Regards,
VELU</p>

<blockquote>
  <p>Blockquote</p>
</blockquote>

<p>After some googling i have got this way to do so. Finally it works.</p>

<blockquote>
  <p>Blockquote</p>
</blockquote>

<pre><code>           SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date endDate = null;
    try {
        endDate = formatter.parse(tochangeDate);
    } catch (ParseException e) {
    }
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date startDate = null;

    String curentDateandTime = sdf.format(new Date());
    try {
        startDate = formatter.parse(curentDateandTime);
    } catch (ParseException e) {
    }

    long diff = (startDate.getTime()) - (endDate.getTime());

    int numOfDays = (int) (diff / (1000 * 60 * 60 * 24));
    int hours = (int) (diff / (1000 * 60 * 60));
    int minutes = (int) (diff / (1000 * 60));
    int seconds = (int) (diff / (1000));
</code></pre>

<p>This is what i have done and it works charm</p>
