3

I want to get how much date,hours,minutes and second remaining form Date1

String RemainingOn = "2013/25/1 22:36:24";
String mDate,mHour,mMinute,mSecond;

public String  DateComparedateTime()
{
 // compare  RemainingOn with now 
   mDate = Difference date with RemainingOn and Now;
   mHour = Difference hour with RemainingOn and Now;
   mMinute = Difference minute with RemainingOn and Now;
   mSecond = Difference second with RemainingOn and Now;

   return mDate+","+mHour+","+mMinute+","+mSecond ;
}
Saeed Hashemi
  • 984
  • 4
  • 22
  • 55

1 Answers1

2

following code gives idea

public String getDateDiffString(Date dateOne, Date dateTwo)
{
    long timeOne = dateOne.getTime();
    long timeTwo = dateTwo.getTime();
    long oneDay = 1000 * 60 * 60 * 24;
    long delta = (timeTwo - timeOne) / oneDay;

    if (delta > 0) {
        return "dateTwo is " + delta + " days after dateOne";
    }
    else {
        delta *= -1;
        return "dateTwo is " + delta + " days before dateOne";
    }
}

if you can use Joda Time

Joda Time has a concept of time Interval:

Interval interval = new Interval(oldTime, new Instant());
TheWhiteRabbit
  • 15,480
  • 4
  • 33
  • 57