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
          主站蜘蛛池模板: 平顺县| 郓城县| 平湖市| 临猗县| 孝感市| 宝应县| 遂溪县| 扬州市| 宾阳县| 静海县| 彩票| 长沙县| 息烽县| 富蕴县| 莱州市| 博兴县| 余姚市| 东阳市| 涞水县| 织金县| 河池市| 清流县| 盘锦市| 威宁| 临漳县| 余庆县| 龙川县| 怀柔区| 象州县| 宁波市| 普格县| 六安市| 镇原县| 厦门市| 江川县| 格尔木市| 弋阳县| 平塘县| 互助| 枣强县| 西乌珠穆沁旗|