大家好,先看看我的代码,int DiffDate;java.sql.Date currentdate = new java.sql.Date(System.currentTimeMillis());

DiffDate = StartDate.getDate() - currentdate.getDate();假设当前日期9月16号。
如果StartDate.getDate()是9月17号,那么DiffDate为1,
但是当我StartDate.getDate()选择为是10月17号 那么DiffDate还是为1,
好像只是算出了日的天数,而没有牵扯到月,
请教各位有没有什么好方法,(java.sql.Date currentdate 尽量不要变)

解决方案 »

  1.   

    还是用Joda-Timepublic class JodaTimeTest {
    public static void main(String[] args) {
    DateTime time1 = new DateTime(2008,8,8,20,8,8,0);//开幕式的时间
    DateTime time2 = new DateTime();//默认当前时间
    Days daysBetween = Days.daysBetween(time1, time2);
    System.out.println(daysBetween.getDays());
    }
    }
      

  2.   

    DiffDate = (StartDate.getTime() - currentdate.getTime())/86400000;  这种方法呢  如何?
      

  3.   

    Welcome to my blog to read: Java中的日期时间.
    Please give me some advice.http://blog.csdn.net/justinavril/archive/2008/09/06/2891266.aspx
      

  4.   


    你好,你Days daysBetween = Days.daysBetween(time1, time2);
    中的Days我的系统没有这么个类型呀?我需要怎么导入呢 ?
      

  5.   

    http://bbs.tarena.com.cn/去这里也能解决!
      

  6.   


    我也很希望知道这个改导入那个包 java.util?
      

  7.   

    long chngDate = calendarChngDate.getTimeInMillis(); 
    long unyouhidukeDate = calendarUnyouhiduke.getTimeInMillis(); 
    long validateDate = (chngDate - unyouhidukeDate) / (1000 * 60 * 60 * 24); 
    "calendarChngDate"  和“calendarUnyouhiduke” 两个日期
      

  8.   

    Joda-Time是个Jar包,需要单独下载的.不是JDK本身的东西.
    从Google上搜索一下.就能马上找到下载的链接了.