java學習

          java學習

           

          java年月日的操作

           public static List<String> getWeekDay(String strDate) {
                   List<String> list = new ArrayList<String>();//第幾周,周幾
                      String nReturn = null;
                      Calendar c = Calendar.getInstance(); // 實例化一個Calendar對象
                      c.clear(); // 清空Calendar
                      c.set(Integer.parseInt(strDate.substring(0, 4)), Integer
                              .parseInt(strDate.substring(5, 7)) - 1, Integer
                              .parseInt(strDate.substring(8, 10))); // 設置這個日期的內容
                      System.out.println("------------" + c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH) + 1) + "月"+(c.get(Calendar.DATE))+"日的天數和周數-------------");  
                      System.out.println("天數:" + c.getActualMaximum(Calendar.DAY_OF_MONTH));  
                      System.out.println("周數:" + c.getActualMaximum(Calendar.WEEK_OF_MONTH));
                      System.out.println("第幾周:"+c.get(Calendar.DAY_OF_WEEK_IN_MONTH));
                      switch (c.get(Calendar.DAY_OF_WEEK)) {
                      case 1:
                          nReturn = "7";
                          break;
                      case 2:
                          nReturn = "1";
                          break;
                      case 3:
                          nReturn = "2";
                          break;
                      case 4:
                          nReturn = "3";
                          break;
                      case 5:
                          nReturn = "4";
                          break;
                      case 6:
                          nReturn = "5";
                          break;
                      case 7:
                          nReturn = "6";
                          break;
                      default:
                          nReturn = null;
                          break;
                      }
                      list.add(String.valueOf(c.get(Calendar.DAY_OF_WEEK_IN_MONTH)));
                      list.add(nReturn);
                      return list;
                  }

          posted on 2013-03-12 14:14 楊軍威 閱讀(289) 評論(0)  編輯  收藏


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


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 宣武区| 新蔡县| 岐山县| 东至县| 荣成市| 龙口市| 辉县市| 永顺县| 平塘县| 昌黎县| 奉贤区| 渝北区| 陇川县| 龙岩市| 扶余县| 石门县| 绥棱县| 商水县| 江口县| 平山县| 新竹市| 深泽县| 谢通门县| 奉化市| 祁阳县| 彭泽县| 安康市| 慈利县| 禄劝| 上林县| 河曲县| 昌都县| 涞水县| 吴川市| 乐山市| 聂拉木县| 镇巴县| 彰化市| 邢台市| 兰坪| 侯马市|