3

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 ;
}
4

1 に答える 1

2

次のコードはアイデアを与える

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";
    }
}

Joda Timeを使用できる場合

Joda Time には、時間間隔の概念があります。

Interval interval = new Interval(oldTime, new Instant());
于 2013-01-16T06:18:12.727 に答える