熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

得到兩個日期之間的間隔天數

2013-11-23 18:41:43  來源: Java核心技術 

  public static int getDaysBetween (String beginDate String endDate) throws ParseException

  {

  SimpleDateFormat format = new SimpleDateFormat(yyyyMMdd);

  Date bDate = formatparse(beginDate);

  Date eDate = formatparse(endDate);

  Calendar d = new GregorianCalendar();

  dsetTime(bDate);

  Calendar d = new GregorianCalendar();

  dsetTime(eDate);

  int days = dget(CalendarDAY_OF_YEAR) dget(CalendarDAY_OF_YEAR);

  int y = dget(CalendarYEAR);

  if (dget(CalendarYEAR) != y)

  {

  d = (Calendar) dclone();

  do   {

  days += dgetActualMaximum(CalendarDAY_OF_YEAR);//得到當年的實際天數

  dadd(CalendarYEAR );

  }    while (dget(CalendarYEAR) != y);

  }

  return days;

  }


From:http://tw.wingwit.com/Article/program/Java/hx/201311/25589.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.