ZhipSoft.com
              冬去春來
                  鄭重聲明:本Blog純屬個人學(xué)習、工作需要,記錄相關(guān)資料。請不要發(fā)表任何有人身攻擊的言論,謝謝!!www.ZhipSoft.com
          posts - 94,comments - 149,trackbacks - 0
          java得到指定時間段中的所有周,以及每周的每天都是周幾和日期是多少?

          第一周的開始一天不一定是周一,最后一周的結(jié)束一天也不一定是周日! 



           public static void main(String[] args){
           
            Calendar c_begin = new GregorianCalendar();
               Calendar c_end = new GregorianCalendar();
               DateFormatSymbols dfs = new DateFormatSymbols();
               String[] weeks = dfs.getWeekdays();
              
               c_begin.set(2010, 3, 2); //Calendar的月從0-11,所以4月是3.
               c_end.set(2010, 4, 20); //Calendar的月從0-11,所以5月是4.

               int count = 1;
               c_end.add(Calendar.DAY_OF_YEAR, 1);  //結(jié)束日期下滾一天是為了包含最后一天
              
               while(c_begin.before(c_end)){
             System.out.println("第"+count+"周  日期:"+new java.sql.Date(c_begin.getTime().getTime())+", "+weeks[c_begin.get(Calendar.DAY_OF_WEEK)]);

                if(c_begin.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
                 count++;
                }
                c_begin.add(Calendar.DAY_OF_YEAR, 1);
               }
              
          }

                  本Blog純屬個人學(xué)習、工作需要,記錄相關(guān)資料。請不要發(fā)表任何有人身攻擊的言論,謝謝! www.zhipsoft.cn
          posted on 2010-04-08 11:07 ZhipSoft 閱讀(1496) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 乐清市| 钦州市| 蚌埠市| 凤翔县| 平定县| 贵南县| 宁海县| 陆良县| 板桥市| 闽侯县| 工布江达县| 延长县| 五峰| 万荣县| 萝北县| 峨眉山市| 彭水| 白水县| 蓝田县| 马山县| 邻水| 晋宁县| 福鼎市| 临城县| 永宁县| 贵定县| 同江市| 宜良县| 于都县| 马龙县| 墨江| 平潭县| 福泉市| 司法| 明溪县| 济源市| 巴楚县| 五峰| 区。| 陕西省| 平山县|