title: How to compare two timestamps in android?
body: <p>I want to compare two timestamps  and if the difference of that is (-+5minuts) then I want to display alert dialog. </p>
  
  <p>i.e. If currently in our watch 4PM the second time is 4.05PM or 3.55PM then alert will display else not.</p>
  
  <p>Can anyone suggest me the way how can I get the solution of this.??</p>
  
  <p>I found after search the function of getting timeStamp and how to compare two timestamps but for this type of condition is there any method or function?</p>
  
  <p>Thanks.</p>
  
  <p>My code is:- </p>
  
  <pre><code>date= new Date();
  currentTime = date.getTime();
  if(currentTime !=0 &amp;&amp; previousTime !=0){
     String result = (String) DateUtils.getRelativeTimeSpanString(currentTime, previousTime, 0);
   }
  </code></pre>
  
  <p>And I am storeing current time in to previous time lilke tis way :-</p>
  
  <pre><code>if(currentTime != previousTime){
      previousTime = currentTime;
  }
  </code></pre>