比较Android中两个日期时间日期、两个、时间、Android

2023-09-07 13:56:04 作者:怎么爽怎么做

我想了一个方法来比较DATE2(现在的)日期1(2013年1月21日二十一时22分30秒)

我想获得多少日期,小时,分钟和秒形式剩余1日

 字符串mDate,mHour,mMinute,mSecond;DateComparedateTime(字符串日期1){ //现在用比较日期1   mDate =差日期date1和现在;   mHour =与date1和现在差别小时;   mMinute =差与分钟date1和现在;   mSecond =差第二,date1和现在;} 

如何创造这个方法?

解决方案

 日历的currentdate = Calendar.getInstance();      SimpleDateFormat的SDF =新的SimpleDateFormat(MM / DD / YYYY);    串dateNow = sdf.format(currentDate.getTime());      今天的日期=新的日期(dateNow);      日期finalDay = NULL;      finalDay =(日期)sdf.parse(MM / DD / YYYY);    INT NUMBEROFDAYS =(int)的((finalDay.getTime() -  today.getTime())/(3600 * 24 * 1000)); 

Android 时间同步机制及常见问题分析

I want to compare date1(2013/1/21 21:22:30) with date2(now) in one method

I want to get how much date,hours,minutes and second Remaining form Date 1

String mDate,mHour,mMinute,mSecond;

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

how can create this method ?

解决方案

Calendar currentDate = Calendar.getInstance();
      SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");


    String dateNow = sdf.format(currentDate.getTime());
      Date today =  new Date(dateNow);
      Date finalDay = null;
      finalDay = (Date) sdf.parse("MM/dd/yyyy");
    int numberOfDays=(int)((finalDay.getTime()-today.getTime())/(3600*24*1000));

 
精彩推荐
图片推荐