Date(long date) 
          Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
----------用这个方法

解决方案 »

  1.   

    public long daysBetween(String sourceDay1, String sourceDay2)
      {
        long days = -1;
        if(sourceDay1 != null && sourceDay2 != null && (isStandardDate(sourceDay1) || isFormatDate(sourceDay1) || isStandardDate(sourceDay2) || isFormatDate(sourceDay2)))
        {
          SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
          try
          {
            if(isFormatDate(sourceDay1))
            {
              sourceDay1 = toStandardDate(sourceDay1);
            }
            if(isFormatDate(sourceDay2))
            {
              sourceDay2 = toStandardDate(sourceDay2);
            }
            Date day1 = sdf.parse(sourceDay1);
            Date day2 = sdf.parse(sourceDay2);
            days = (day1.getTime() - day2.getTime()) / (24 * 3600 * 1000);
            days = Math.abs(days);
          }
          catch(ParseException e)
          {
            if(e != null)
            {
              e.printStackTrace();
              System.out.println("日期转换出错:" + e.getMessage());
            }
          }
        }
        return days;
      }public String dateAdjust(String sourceString, int addDays, int format, boolean keepEightBit)
      {
        String returnString = sourceString;
        if(isStandardDate(sourceString) || isFormatDate(sourceString))
        {
          if(isFormatDate(sourceString))
          {
            sourceString = toStandardDate(sourceString);
          }
          SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
          Date dt = sdf.parse(sourceString, new ParsePosition(0));
          Calendar cal = Calendar.getInstance();
          cal.setTime(dt);
          cal.add(cal.DATE, addDays);
          Date dt1 = cal.getTime();
          StringBuffer strBuffer = new StringBuffer();
          strBuffer.append("");
          returnString = sdf.format(dt1, strBuffer, new FieldPosition(0)).toString();
          returnString = toFormatDate(returnString, format, keepEightBit);
        }
        return returnString;
      }
      

  2.   

    不好意思,把上面的第二个方法改一改:
    public String dateAdjust(String sourceString, int addDays, )
      {
        String returnString = sourceString;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Date dt = sdf.parse(sourceString, new ParsePosition(0));
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        cal.add(cal.DATE, addDays);
        Date dt1 = cal.getTime();
        StringBuffer strBuffer = new StringBuffer();
        strBuffer.append("");
        returnString = sdf.format(dt1, strBuffer, new FieldPosition(0)).toString();
        return returnString;
      }
      

  3.   

    long lBeginTime = new java.util.Date().getTime() ;
    long lEndTime = new java.util.Date().getTime() ;
    int iDay = (int)((lBeginTime-lEndTime)/86400000);//新的天数