posts - 0,  comments - 5,  trackbacks - 0
          /** **對時間周的處理?傳入{"2008-05-25","2008-07-5"},返回{2008-6-23,2008-6-29,2008-6-30,2008-7-6}****** */
          ????
          public ? static ?String[]?getBeginAndEndWeek(String?dateBeg,String?dateEnd)
          ????
          {
          ????????String?temp?
          = ? "" ;
          ????????String[]?tempArr?
          = ? null ;
          ????????Date?begin?
          = ?formatDate(dateBeg);
          ????????GregorianCalendar?date1?
          = ? new ?GregorianCalendar();
          ????????date1.setTime(begin);
          ????????
          int ?DAY_OF_WEEK1? = ?date1.get(GregorianCalendar.DAY_OF_WEEK);
          ????????
          if (DAY_OF_WEEK1 == 2 )
          ????????
          {
          ????????}
          else
          ????????
          {
          ????????????
          int ?changeDay? = ?DAY_OF_WEEK1 - 2 ;
          ????????????
          if (changeDay ==- 1 )?changeDay? = ? 6 ;
          ????????????date1.set(GregorianCalendar.DATE,?date1.get(Calendar.DATE)
          - changeDay);
          ????????}

          ????????
          ????????Date?end?
          = ?formatDate(dateEnd);
          ????????GregorianCalendar?date2?
          = ? new ?GregorianCalendar();
          ????????date2.setTime(end);
          ????????
          int ?DAY_OF_WEEK2? = ?date2.get(GregorianCalendar.DAY_OF_WEEK);
          ????????
          if (DAY_OF_WEEK2 == 1 )
          ????????
          {
          ????????}
          else
          ????????
          {
          ????????????
          int ?changeDay? = ? 8 - DAY_OF_WEEK2;
          ????????????date2.set(GregorianCalendar.DATE,?date2.get(Calendar.DATE)
          + changeDay);
          ????????}

          ????????
          ????????GregorianCalendar?date3?
          = ? new ?GregorianCalendar();
          ????????date3.setTime(date1.getTime());
          ????????date3.add(Calendar.DATE,?
          - 1 );
          ????????
          if (date1.compareTo(date2) ==- 1 )
          ????????
          {
          ????????????temp?
          = ?temp? + ?formatDate(date1.getTime())? + " , " ;
          ????????????date1.add(Calendar.DATE,?
          7 );
          ????????????date3.add(Calendar.DATE,?
          7 );
          ????????????
          while (date1.compareTo(date2) ==- 1 )
          ????????????
          {
          ????????????????temp?
          = ?temp? + ?formatDate(date3.getTime()) + " , " + formatDate(date1.getTime())? + " , " ;
          ????????????????date3.add(Calendar.DATE,?
          7 );
          ????????????????date1.add(Calendar.DATE,?
          7 );
          ????????????}

          ????????????temp?
          = ?temp? + ?formatDate(date2.getTime())? + " , " ;
          ????????}
          else
          ????????
          {
          ????????????date2.setTime(date1.getTime());
          ????????????date2.add(Calendar.DATE,?
          6 );
          ????????????temp?
          = ?formatDate(date1.getTime()) + " , " + formatDate(date2.getTime()) + " , " ;
          ????????}

          ????????
          if (temp.length() > 1 )
          ????????
          {
          ????????????tempArr?
          = ?temp.split( " , " );
          ????????????
          for ( int ?i = 0 ;?i < tempArr.length;?i ++ )
          ????????????
          {
          ????????????????System.out.println(tempArr[i]);
          ????????????}

          ????????}

          ????????
          return ?tempArr;
          ????}



          public ? static ?Date?formatDate(String?date)
          ????
          {
          ????????Date?d1?
          = ? new ?Date();
          ????????
          if (date == null ? || ?date.equals( "" ))? return ? new ?Date();
          ????????
          try
          ????????
          {
          ????????????DateFormat?df?
          = ? new ?SimpleDateFormat( " yyyy-MM-dd " );
          ????????????d1?
          = ?df.parse(date);
          ????????}

          ????????
          catch (Exception?ex)
          ????????
          {
          ????????????
          ????????}

          ????????
          return ?d1;
          ????????
          ????}
          posted on 2008-06-25 22:36 crazy 閱讀(92) 評論(0)  編輯  收藏 所屬分類: java
          主站蜘蛛池模板: 安康市| 亚东县| 项城市| 达拉特旗| 温宿县| 轮台县| 县级市| 美姑县| 绍兴市| 新巴尔虎右旗| 阳谷县| 安国市| 江西省| 兴文县| 顺义区| 鄯善县| 抚顺县| 崇明县| 灌南县| 贡嘎县| 乳源| 闵行区| 广宗县| 伊宁县| 聂拉木县| 察哈| 兴隆县| 泽州县| 合阳县| 咸宁市| 友谊县| 陵水| 措勤县| 东阳市| 旬邑县| 新昌县| 平果县| 三江| 盘锦市| 江门市| 大荔县|