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
          主站蜘蛛池模板: 东乡县| 桃源县| 城口县| 大荔县| 固阳县| 长丰县| 巩义市| 肇源县| 繁昌县| 巴彦县| 铅山县| 平湖市| 唐河县| 那坡县| 来宾市| 成都市| 福清市| 赞皇县| 海伦市| 乌拉特前旗| 崇仁县| 文化| 澜沧| 定南县| 河北省| 海口市| 河东区| 齐河县| 搜索| 平阴县| 清镇市| 沽源县| 咸丰县| 琼结县| 蛟河市| 铅山县| 分宜县| 汉寿县| 商水县| 荥经县| 凤山市|