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
          主站蜘蛛池模板: 开阳县| 临江市| 龙江县| 略阳县| 辛集市| 娄底市| 泰顺县| 罗城| 广昌县| 拉萨市| 赞皇县| 永定县| 镇巴县| 寿阳县| 法库县| 黄山市| 东丰县| 上林县| 保靖县| 安吉县| 蛟河市| 霍州市| 南木林县| 静安区| 金乡县| 延寿县| 文水县| 隆子县| 保康县| 皮山县| 周宁县| 神木县| 滁州市| 察雅县| 晋江市| 惠来县| 武山县| 盘锦市| 沂水县| 姚安县| 晋江市|